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 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
101010101010101010101010101010101010101010101
www.bosscoderacademy.com
Introduction
Online resources to practise DSA problems have
thousands of questions over a wide range of topics.
ARRAYS
Question 1.
Write a program to reverse an array
Practice Here
Question 2.
Find the kth smallest element in an array in linear
time complexity.
Practice Here
Question 3.
Given an integer array arr, find the contiguous
subarray (containing at least one number) which
has the largest sum and return its sum and print
the subarray.
Practice Here
Question 4.
Practice Here
Question 5.
constant space.
Practice Here
Question 6.
Practice Here
Question 7.
add up to target.
Practice Here
Question 8.
Practice Here
STRINGS
Question 1.
Write a function that reverses a string. The input
string is given as an array of characters s. You must
do this by modifying the input array in-place with
O(1) extra memory.
Practice Here
Question 2.
Given a string str of length N, you have to find the
number of palindromic subsequences (need not
necessarily be distinct) present in the string str.
Practice Here
Question 3.
Practice Here
Question 4.
Practice Here
Question 5.
Practice Here
Question 6.
Practice Here
SEARCHING AND SORTING
ALGORITHMS
Question 1.
Given an array of integers nums which is sorted in
ascending order, and an integer target, write a
function to search target in nums. If target exists,
then return its index. Otherwise, return -1. You must
write an algorithm with O(log n) runtime
complexity.
Practice Here
Question 2.
Given two sorted arrays nums1 and nums2 of size m
and n respectively, return the median of the two
sorted arrays. The overall run time complexity
should be O(log (m+n)).
Practice Here
Question 3.
Practice Here
Question 4.
Practice Here
RECURSION
Question 1.
parentheses.
Practice Here
Question 2.
Practice Here
Question 3.
Practice Here
Question 4.
Practice Here
Question 5.
Given a collection of candidate numbers
(candidates) and a target number (target), find all
unique combinations in candidates where the
candidate numbers sum to target.
Practice Here
HASHING
Question 1.
Given an array of integers nums and an integer
target, return indices of the two numbers such that
they add up to target.
Practice Here
Question 2.
Given an unsorted integer array nums, return the
smallest missing positive integer.
Practice Here
Question 3.
Practice Here
Question 4.
Practice Here
MATRICES AND
MULTIDIMENSIONAL ARRAYS
Question 1.
Given an m x n matrix, return all elements of the
matrix in spiral order.
Practice Here
Question 2.
Given an m x n integer matrix matrix, if an element
is 0, set its entire row and column to 0's.
following rules:
repetition.
repetition.
Practice Here
Question 4.
Practice Here
Question 5.
Write an efficient algorithm that searches for a
value target in an m x n integer matrix matrix. This
matrix has the following properties:
Practice Here
LINKED LIST
Question 1.
Given the head of a singly linked list, reverse the list,
and return the reversed list.
Practice Here
Question 2.
Given head, the head of a linked list, determine if
the linked list has a cycle in it.
Practice Here
Question 3.
Practice Here
Question 4.
Practice Here
Question 5.
You are given the head of a singly linked-list. The list
can be represented as:
L0 → L1 → … → Ln - 1 → Ln
L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
Practice Here
Question 6.
Given elements as nodes of the two linked lists. The
task is to multiply these two linked lists, say L1 and
L2.
Practice Here
Question 7.
Practice Here
Question 8.
Practice Here
Question 9.
Practice Here
Question 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.
Practice Here
BIT MANIPULATION & MATH
CONCEPTS
Question 1.
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.
Practice Here
Question 2.
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.
Practice Here
Question 3.
single one.
space.
Practice Here
Question 4.
it.
Practice Here
Question 5.
Given two integer arrays nums1 and nums2, return
an array of their intersection. Each element in the
result must appear as many times as it shows in
both arrays and you may return the result in any
order.
Practice Here
STACKS AND QUEUES
Question 1.
Implement a first in first out (FIFO) queue using
only two stacks. The implemented queue should
support all the functions of a normal queue (push,
peek, pop, and empty).
Practice Here
Question 2.
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).
Practice Here
Question 3.
Practice Here
Question 4.
histogram.
Practice Here
Question 5.
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.
Practice Here
Question 6.
Given a string s containing just the characters '(', ')',
'{', '}', '[' and ']', determine if the input string is valid.
Practice Here
Question 7.
Given a Queue Q containing N elements. The task is
to reverse the Queue. Your task is to complete the
function rev(), that reverses the N elements of the
queue.
Practice Here
Question 8.
Practice Here
Question 9.
Practice Here
Question 10.
You are given an array of integers nums, there is a
sliding window of size k which is moving from the
very left of the array to the very right. You can only
see the k numbers in the window. Each time the
sliding window moves right by one position.
Practice Here
Question 11.
Design a stack that supports push, pop, top, and
retrieving the minimum element in constant time.
Practice Here
Question 12.
You are given an m x n grid where each cell can
have one of three values:
Practice Here
TREES & BINARY SEARCH
TREES
Question 1.
Given the root of a binary tree, return its maximum
depth.
Question 2.
Given the root of a binary tree, invert the tree, and
return its root.
Practice Here
Question 3.
Practice Here
Question 4.
value.
Practice Here
Question 5.
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).
Practice Here
Question 6.
Given a binary tree, find the lowest common
ancestor (LCA) of two given nodes in the tree.
Practice Here
Question 7.
Given two integer arrays preorder and inorder
where preorder is the preorder traversal of a binary
tree and inorder is the inorder traversal of the same
tree, construct and return the binary tree.
Practice Here
Question 8.
Practice Here
Question 9.
Practice Here
Question 10.
Practice Here
Question 11.
left to right, then right to left for the next level and
alternate between).
Practice Here
Question 12.
balanced
Practice Here
TRIES
Question 1.
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.
Practice Here
Question 2.
Design a data structure that supports adding new
words and finding if a string matches any previously
added string.
Practice Here
Question 3.
Practice Here
Question 4.
words.
Practice Here
Question 5.
Given an m x n board of characters and a list of
strings words, return all words on the board.
Practice Here
HEAPSt
Question 1.
You are given an array of k linked-lists lists, each
linked-list is sorted in ascending order.
Practice Here
Question 2.
Given an integer array nums and an integer k,
return the k most frequent elements. You may
return the answer in any order.
Practice Here
Question 3.
if not possible.
Practice Here
Question 4.
Practice Here
GRAPHS
Question 1.
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.
Practice Here
Question 2.
Given an m x n binary matrix mat, return the
distance of the nearest 0 for each cell.
Practice Here
Question 3.
Search
Practice Here
Question 4.
shortest path.
Practice Here
Question 5.
Spanning Tree
Practice Here
Question 6.
graph.
Practice Here
Question 7.
Practice Here
Question 8.
Practice Here
Question 9.
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].
Practice Here
Question 10.
Given a graph, find the topological order for the
given graph.t
Practice Here
DYNAMIC PROGRAMMING
AND GREEDY
Question 1.
Given an integer array nums, find a subarray that
has the largest product, and return the product.
Practice Here
Question 2.
Given an integer array nums, return the length of
the longest strictly increasing subsequence
Practice Here
Question 3.
word1 to word2.
on a word:
Insert a character
Delete a character
Replace a character
Practice Here
Question 4.
Practice Here
Question 5.
You are given an integer array coins representing
coins of different denominations and an integer
amount representing a total amount of money.
Practice Here
Question 6.
Given two strings text1 and text2, return the length
of their longest common subsequence. If there is no
common subsequence, return 0.
Practice Here
Question 7.
(i.e., grid[m - 1][n - 1]). The robot can only move either
Practice Here
Question 8.
words.
Practice Here
Question 9.
Given a set of N jobs where each job has a deadline
and profit associated with it.
Practice Here
Question 10.
Given weights and values of N items, we need to
put these items in a knapsack of capacity W to get
the maximum total value in the knapsack.
Practice Here
Why
Bosscoder?
1000+ Alumni placed at Top
Product-based companies.
Explore More