0% found this document useful (0 votes)
5 views

Coding Questions

The document outlines 50 commonly asked coding problems across various topics such as arrays, strings, recursion, and dynamic programming, aimed at helping individuals prepare for tech interviews. Each problem includes a brief description and indicates that it has been asked in practice settings. Additionally, the document promotes Bosscoder, highlighting the success of its alumni in securing positions at top companies and achieving significant salary hikes.

Uploaded by

abwaheed.ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Coding Questions

The document outlines 50 commonly asked coding problems across various topics such as arrays, strings, recursion, and dynamic programming, aimed at helping individuals prepare for tech interviews. Each problem includes a brief description and indicates that it has been asked in practice settings. Additionally, the document promotes Bosscoder, highlighting the success of its alumni in securing positions at top companies and achieving significant salary hikes.

Uploaded by

abwaheed.ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

50 Most Asked

Coding Problem

Crack your Next Tech Interview


*Disclaimer*
Everyone learns uniquely.

What matters is developing the problem


solving ability to solve new problems.

This Doc will help you with the same.

1
Arrays
Given an array of integers and an integer target, return indices of the
two numbers such that they add up to target.
Asked in :

Practice

Given an integer array nums, find the subarray with the largest sum,
and return its sum.
Asked in :

Practice

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.
Asked in :

Practice

2
Given an array nums of n integers, return an array of all the unique
quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

0 <= a, b, c, d < n

a, b, c, and d are distinct.

nums[a] + nums[b] + nums[c] + nums[d] == target


Asked in :

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.
Asked in :

Practice

3
Strings
Given a string s of '(' , ')' and lowercase English characters.

Your task is to remove the minimum number of parentheses ( '(' or ')',


in any positions ) so that the resulting parentheses string is valid and
return any valid string.
Asked in :

Practice

Given a string s, sort it in decreasing order based on the frequency


of the characters. The frequency of a character is the number of
times it appears in the string.

Return the sorted string. If there are multiple answers, return any of
them.
Asked in :

Practice

4
Given two strings s1 and s2, return true if s2 contains a permutation
of s1, or false otherwise.

In other words, return true if one of s1's permutations is the substring


of s2.
Asked in :

Practice

Given a string s, partition s such that every

Substring of the partition is a Palindrome. Return all possible


palindrome partitioning of s.
Asked in :

Practice

Given two strings s and t of lengths m and n respectively, return the


minimum window

Substring of s such that every character in t (including duplicates) is


included in the window. If there is no such substring, return the
empty string "".
Asked in :

Practice

5
Recursion
Given the head of a linked list and an integer val, remove all the
nodes of the linked list that has Node.val == val, and return the new
head.
Asked in :

Practice

Given the head of a singly linked list, reverse the list, and return the
reversed list.
Asked in :

Practice

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
Asked in :

Practice

6
Given n pairs of parentheses, write a function to generate all
combinations of well-formed parentheses.
Asked in :

Practice

7
Hashing
Design a data structure that follows the constraints of a Least
Recently Used (LRU) cache.
Asked in :

Practice

Given an unsorted integer array nums, return the smallest missing


positive integer.

You must implement an algorithm that runs in O(n) time and uses
constant extra space.
Asked in :

Practice

8
Matrices
Given an m x n matrix, return all elements of the matrix in spiral order.
Asked in :

Practice

Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need


to be validated according to the following rules:

Each row must contain the digits 1-9 without repetition.

Each column must contain the digits 1-9 without repetition.

Each of the nine 3 x 3 sub-boxes of the grid must contain the digits
1-9 without repetition.
Asked in :

Practice

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.
Asked in :

Practice

9
Linked List
Given the root of a binary tree, flatten the tree into a "linked list":

The "linked list" should use the same TreeNode class where the right
child pointer points to the next node in the list and the left child
pointer is always null.

The "linked list" should be in the same order as a pre-order traversal


of the binary tree.
Asked in :

Practice

Given the head of a singly linked list, return true if it is a palindrome


or false otherwise.
Asked in :

Practice

10
Given the head of a linked list, reverse the nodes of the list k at a
time, and return the modified list. k is a positive integer and is less
than or equal to the length of the linked list. If the number of nodes is
not a multiple of k then left-out nodes, in the end, should remain as it
is.

You may not alter the values in the list's nodes, only nodes
themselves may be changed.

Asked in :

Practice

You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists in a one sorted list. The list should be made by
splicing together the nodes of the first two lists.

Return the head of the merged linked list.

Asked in :

Practice

11
You are given two non-empty linked lists representing two non-
negative integers. The digits are stored in reverse order, and each of
their nodes contains a single digit. Add the two numbers and return
the sum as a linked list.

You may assume the two numbers do not contain any leading zero,
except the number 0 itself.
Asked in :

Practice

Given a linked list, swap every two adjacent nodes and return its
head. You must solve the problem without modifying the values in
the list's nodes (i.e., only nodes themselves may be changed.)
Asked in :

Practice

12
Bit Manipulation and Math
Given an array nums containing n distinct numbers in the range [0,
n], return the only number in the range that is missing from the array.
Asked in :

Practice

Given an integer n, return an array ans of length n + 1 such that for


each i (0 <= i <= n), ans[i] is the number of 1's in the binary
representation of i.
Asked in :

Practice

13
Stacks and Queues
Given an array of integers heights representing the histogram's bar
height where the width of each bar is 1, return the area of the largest
rectangle in the histogram.
Asked in :

Practice

Design a stack that supports push, pop, top, and retrieving the
minimum element in constant time.
Asked in :

Practice

Implement a last-in-first-out (LIFO) stack using only two queues. The


implemented stack should support all the functions of a normal stack
(push, top, pop, and empty).
Asked in :

Practice

14
Implement the BSTIterator class that represents an iterator over the
in-order traversal of a binary search tree (BST)
Asked in :

Practice

Given n non-negative integers representing an elevation map where


the width of each bar is 1, compute how much water it can trap after
raining.
Asked in :

Practice

15
Trees and Binary Search Trees
Given the root of a binary tree, return its maximum depth.

A binary tree's maximum depth is the number of nodes along the


longest path from the root node down to the farthest leaf node.
Asked in :
Practice

Given a binary tree, find the lowest common ancestor (LCA) of two
given nodes in the tree.
Asked in :
Practice

Given the root of a binary search tree, and an integer k, return the
kth smallest value (1-indexed) of all the values of the nodes in the
tree.
Asked in :
Practice

16
Given the root of a binary tree, return the level order traversal of its
nodes' values. (i.e., from left to right, level by level).
Asked in :

Practice

You are given the root of a binary tree containing digits from 0 to 9
only.

Each root-to-leaf path in the tree represents a number.

For example, the root-to-leaf path 1 -> 2 -> 3 represents the number
123.Return the total sum of all root-to-leaf numbers. Test cases are
generated so that the answer will fit in a 32-bit integer.
Asked in :

Practice

Given the roots of two binary trees root and subRoot, return true if
there is a subtree of root with the same structure and node values of
subRoot and false otherwise.
Asked in :

Practice

17
Tries
A trie (pronounced as "try") or prefix tree is a tree data structure
used to efficiently store and retrieve keys in a dataset of strings.
There are various applications of this data structure, such as
autocomplete and spellchecker.

Implement the Trie.


Asked in :

Practice

Given an array of strings strs, group the anagrams together. You can
return the answer in any order.
Asked in :

Practice

18
Heaps
You are given an array of k linked-lists lists, each linked-list is sorted
in ascending order.

Merge all the linked-lists into one sorted linked-list and return it.
Asked in :

Practice

The median is the middle value in an ordered integer list. If the size of
the list is even, there is no middle value, and the median is the mean
of the two middle values.

Implement the MedianFinder class:


Asked in :

Practice

19
Graphs
Given is a 2D adjacency list representation of a graph. Check
whether the graph is a Bipartite graph.
Asked in :

Practice

An image is represented by an m x n integer grid image where


image[i][j] represents the pixel value of the image.

You are also given three integers sr, sc, and color. You should
perform a flood fill on the image starting from the pixel image[sr][sc].
Asked in :

Practice

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.
Asked in :

Practice

20
Given a reference of a node in a connected undirected graph.

Return a deep copy (clone) of the graph.

Asked in :

Practice

Given an m x n integers matrix, return the length of the longest


increasing path in matrix.

From each cell, you can either move in four directions: left, right, up,
or down. You may not move diagonally or move outside the boundary
(i.e., wrap-around is not allowed).

Asked in :

Practice

21
Dynamic Programming
Given an integer array nums, find a subarray that has the largest
product, and return the product.
Asked in :

Practice

Given two strings text1 and text2, return the length of their longest
common subsequence. If there is no common subsequence, return 0.
Asked in :

Practice

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.
Asked in :

Practice

22
Why Bosscoder?
2200+ Alumni placed at Top Product-
based companies.

More than 136% hike for every 



2 out of 3 Working Professional.

Average Package of 24LPA.

Explore More

You might also like