Technical - 30 08 24
Technical - 30 08 24
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
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.
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.
9. Given two non-negative integers num1 and num2 represented as strings, return the
product of num1 and num2, also represented as a string.
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.
function fun(n):
if n <= 1:
return n
return fun(n-1) + fun(n-2)
output = fun(4)
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)
function func(n):
table = ""
for i = 1 to 10:
table = table + (n * i) + " "
return table
output = func(5)
arr = [1, 2, 3, 4, 5, 6]
output = func(arr)
arr = [1, 2, 3, 4]
output = func(arr)
function func(arr):
result = ""
for i = 0 to length(arr) - 1:
result = result + i + ":" + arr[i] + " "
return result
arr = ["a", "b", "c"]
function func(n):
gen = ""
for i = 1 to n:
for j = 1 to i:
gen = gen + "*"
gen = gen + "\n"
return gen
output = func(3)
arr = [4, 7, 1, 3, 7]
output = fun(arr, 7)