Ques Bank Updated

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Data Structures & Algorithms

Arrays & Strings

1. Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0?
Find all unique triplets in the array which gives the sum of zero
2. Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
3. Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j
< k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false
4. Given a string s, return the longest palindromic substring in s
5. Given a string s, find the length of the longest substring without repeating characters
6. Given an array of strings strs, group the anagrams together. You can return the answer
in any order.

Trees & Graphs

1. Kth smallest element in a BST


2. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water),
return the number of islands. An island is surrounded by water and is formed by connecting
adjacent lands horizontally or vertically. You may assume all four edges of the grid are all
surrounded by water
3. Binary Tree Zigzag Level Order Traversal

Backtracking

1. Given an m x n grid of characters board and a string word, return true if word exists in the
grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent
cells are horizontally or vertically neighboring. The same letter cell may not be used more
than once
2. Given an integer array nums of unique elements, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
3. Given an array nums of distinct integers, return all the possible permutations. You can return
the answer in any order.
4. Given a string containing digits from 2-9 inclusive, return all possible letter combinations
that the number could represent. Return the answer in any order. A mapping of digits to
letters is just like on the telephone buttons

Dynamic Programming

1. Given an integer array coins representing coins of different denominations and an


integer amount representing a total amount of money. Return the fewest number of coins
that you need to make up that amount. If that amount of money cannot be made up by any
combination of the coins, return -1. Assume that you have an infinite number of each kind of
coin
2. Given an integer array nums. You are initially positioned at the array's first index, and each
element in the array represents your maximum jump length at that position. Return true if
you can reach the last index, or false otherwise
3. There is a robot on an m x n grid. The robot is initially located at the top-left
corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n
- 1]). The robot can only move either down or right at any point in time. Given the two
integers m and n, return the number of possible unique paths that the robot can take to
reach the bottom-right corner.
4. Given an integer array nums, return the length of the longest strictly increasing subsequence

Sorting & Searching

1. Given an array nums with n objects colored red, white, or blue, sort them in-place so that
objects of the same color are adjacent, with the colors in the order red, white, and blue
2. Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals,
and return an array of the non-overlapping intervals that cover all the intervals in the input.

Others

1. Given a characters array tasks, representing the tasks a CPU needs to do, where each letter
represents a different task. Tasks could be done in any order. Each task is done in one unit of
time. For each unit of time, the CPU could complete either one task or just be idle. However,
there is a non-negative integer n that represents the cooldown period between two same
tasks (the same letter in the array), that is that there must be at least n units of time
between any two same tasks. Return the least number of units of times that the CPU will
take to finish all the given tasks.

You might also like