21. Write a TypeScript function to generate a random UUID.

Required Input:

None

Expected Output:

Generated UUID: a1b2c3d4-e5f6-7890-ab12-cd34ef567890

Code In Typescript

function generateUUID(): string { // Your logic here }

Run Code?

Click Run Button to view compiled output

22. Write a function to debounce an input function with immediate execution support.

Required Input:

Debounced function called multiple times within 2000ms.

Expected Output:

Executed at: <Timestamp>

Code In Typescript

function debounce(fn: Function, delay: number, immediate: boolean = false): Function { // Your logic here }

Run Code?

Click Run Button to view compiled output

23. Write a function to serialize and deserialize a binary tree.

Required Input:

Binary tree: 
 1
 / \ 
 2 3
 / \ 
 4 5

Expected Output:

Serialized Tree: 1,2,null,null,3,4,5,null,null,null,null
Deserialized Tree Root: 1

Code In Typescript

class TreeNode { val: number; left: TreeNode

Run Code?

Click Run Button to view compiled output

24. Write a function to implement the Josephus problem for n people and a step size k.

Required Input:

n = 7
k = 3

Expected Output:

Survivor: 4

Code In Typescript

function josephus(n: number, k: number): number { // Your logic here }

Run Code?

Click Run Button to view compiled output

25. Write a program to find the longest increasing subsequence (LIS) in an array of numbers.

Required Input:

[10, 22, 9, 33, 21, 50, 41, 60, 80]

Expected Output:

Longest Increasing Subsequence: 6

Code In Typescript

function longestIncreasingSubsequence(arr: number[]): number { // Your logic here }

Run Code?

Click Run Button to view compiled output

26. Write a function to calculate the number of islands in a 2D grid where 1 represents land and 0 represents water.

Required Input:

[
 [1, 1, 0, 0, 0],
 [1, 1, 0, 0, 0],
 [0, 0, 1, 0, 0],
 [0, 0, 0, 1, 1]
 ]

Expected Output:

Number of Islands: 3

Code In Typescript

function numIslands(grid: number[][]): number { // Your logic here }

Run Code?

Click Run Button to view compiled output

27. Write a program to find the kth smallest element in an unsorted array.

Required Input:

Array: [7, 10, 4, 3, 20, 15]
k = 3

Expected Output:

Kth Smallest Element: 7

Code In Typescript

function kthSmallest(arr: number[], k: number): number { // Your logic here }

Run Code?

Click Run Button to view compiled output

28. Write a function to merge overlapping intervals in a list of intervals.

Required Input:

[[1, 3], [2, 6], [8, 10], [15, 18]]

Expected Output:

Merged Intervals: [ [ 1, 6 ], [ 8, 10 ], [ 15, 18 ] ]

Code In Typescript

function mergeIntervals(intervals: number[][]): number[][] { // Your logic here }

Run Code?

Click Run Button to view compiled output

29. Write a program to find the maximum profit in a stock market given stock prices for each day.

Required Input:

[7, 1, 5, 3, 6, 4]

Expected Output:

Maximum Profit: 5

Code In Typescript

function maxProfit(prices: number[]): number { // Your logic here }

Run Code?

Click Run Button to view compiled output

ad vertical

3 of 3