0% found this document useful (0 votes)
28 views6 pages

Technical - 30 08 24

psuedo codes

Uploaded by

jogasurya896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Technical - 30 08 24

psuedo codes

Uploaded by

jogasurya896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. Given two sorted arrays of sizes `m` and `n`, find the median of the two sorted arrays.

The overall run time complexity should be `O(log(min(m, n)))`.

Input: nums1 = [1, 3], nums2 = [2]


Output: 2.0

Input: nums1 = [1, 2], nums2 = [3, 4]


Output: 2.5

2. Given a string `s` and a dictionary of words `wordDict`, add spaces in `s` to construct
a sentence where each word is a valid dictionary word. Return all such possible
sentences.
Input: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]
Output: ["cats and dog", "cat sand dog"]

3. Given an array of integers representing the height of bars in a histogram, find the area
of the largest rectangle that can be formed within the histogram.

Input: [2,1,5,6,2,3]
Output: 10

4. Given a collection of intervals, merge all overlapping intervals.

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

Output: [[1,6],[8,10],[15,18]]

5. Given an array of distinct integers candidates and a target integer target, return all
unique combinations in candidates where the candidate numbers sum to target. The
same repeated number may be chosen multiple times.
Input: candidates = [2,3,6,7], target = 7

Output: [[2,2,3],[7]]

6. Given a linked list, reverse the nodes of the list k at a time and return its modified list.
If the number of nodes is not a multiple of k, then left-out nodes in the end should
remain as is.

Input: head = [1,2,3,4,5], k = 3

Output: [3,2,1,4,5]

7. You are climbing a staircase. It takes n steps to reach the top. Each time you can either
climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Input: n = 3
Output: 3 (The distinct ways are [1,1,1], [1,2], [2,1])

8. Given an unsorted array of integers, find the length of the longest consecutive
elements sequence.

Input: [100, 4, 200, 1, 3, 2]


Output: 4 (The longest consecutive sequence is [1, 2, 3, 4])

9. Given two non-negative integers num1 and num2 represented as strings, return the
product of num1 and num2, also represented as a string.

Input: num1 = "123", num2 = "456"


Output: "56088"

10. Given two non-empty linked lists representing two non-negative integers, where each
node contains a single digit, add the two numbers and return it as a linked list. The
digits are stored in reverse order.

Input: l1 = [2,4,3], l2 = [5,6,4]


Output: [7,0,8] (342 + 465 = 807)
11. Find the output of the following pseudo code:

function fun(n):
if n <= 1:
return n
return fun(n-1) + fun(n-2)

output = fun(4)

12. Find the output of the following pseudo code:

function func(arr):
sum = 0
for i = 0 to length(arr) - 1:
sum = sum + arr[i] * arr[i]
return sum
arr = [1, 2, 3]
output = func(arr)

13. Find the output of the following pseudo code:

function func(n):
table = ""
for i = 1 to 10:
table = table + (n * i) + " "
return table

output = func(5)

14. Find the output of the following pseudo code:


function func(arr):
evens = ""
for i = 0 to length(arr) - 1:
if arr[i] % 2 == 0:
evens = evens + arr[i] + " "
return evens

arr = [1, 2, 3, 4, 5, 6]
output = func(arr)

15. Find the output of the following pseudo code:


function func(arr):
count = 0
for i = 0 to length(arr) - 1:
if arr[i] > 0:
count = count + 1
return count

arr = [-1, 2, -3, 4, 5]


output = func(arr)

16. Find the output of the following pseudo code:


function func(n):
result = ""
for i = 1 to n:
result = result + i + ":" + (i * i) + " "
return result
output = func(3)

17. Find the output of the following pseudo code:


function func(arr):
product = 1
for i = 0 to length(arr) - 1:
product = product * arr[i]
return product

arr = [1, 2, 3, 4]
output = func(arr)

18. Find the output of the following pseudo code:

function func(arr):
result = ""
for i = 0 to length(arr) - 1:
result = result + i + ":" + arr[i] + " "
return result
arr = ["a", "b", "c"]

19. Find the output of the following pseudo code:

function func(n):
gen = ""
for i = 1 to n:
for j = 1 to i:
gen = gen + "*"
gen = gen + "\n"
return gen

output = func(3)

20. Find the output of the following pseudo code:


function func (arr, t):
for i = 0 to length(arr) - 1:
if arr[i] == t:
return i
return -1

arr = [4, 7, 1, 3, 7]
output = fun(arr, 7)

You might also like