DSA interview practice
DSA Practice Problems
Pick a problem, work through the algorithm, and use the editor to refine your answer.
Pick a problem to practise
Work through the approach
Move to the next one
Cumulative Sum
The cumulative sum of an array at index i is defined as the sum of all elements of the array from index 0 to index i. Examples Initial Array: [1, 2, 3, 4] Cumulative Sum: [1, 3, 6,…
Browse problems
61 of 61 problems shown
| Problem | Level | Status | Signal | Action |
|---|---|---|---|---|
The cumulative sum of an array at index i is defined as the sum of all elements of the array from index 0 to index i. Examples Initial Array: [1, 2, 3, 4] Cumulative Sum: [1, 3, 6,… Arrays | Easy | Ready | 30 pts No company tags | |
For an array of integers nums , an identical twin is defined as pair (i, j) where nums[i] is equal to nums[j] and i < j . Examples Array: [1, 2, 3, 2, 1] Number of Identical Twi… ArraysHashing | Easy | Ready | 30 pts No company tags | |
Given an array of integers, find the elements which have an even number of digits. Example Array: [42, 564, 5775, 34, 123, 454, 1, 5, 45, 3556, 23442] Answer: 42, 5775, 34, 45, 355… Arrays | Easy | Ready | 30 pts No company tags | |
Given an array, sort it using insertion sort. Testing Input Format The first line contains 'T' denoting the no. of test cases. Next T lines each contain a number 'n' denoting the n… Arrays | Easy | Ready | 30 pts 4 company tags | |
Given two sorted arrays A and B , find the merged sorted array C by merging A and B . Example: A: [1, 2, 3, 4, 4] B: [2, 4, 5, 5] C: [1, 2, 2, 3, 4, 4, 4, 5, 5] Testing Input Forma… ArraysTwo Pointers | Easy | Ready | 30 pts 4 company tags | |
Consider an array that is divided into two parts and both of the parts are sorted individually. Given the mentioned array and the end index of the first part, merge them to create … Arrays | Easy | Ready | 30 pts 1 company | |
Given an array, sort it using merge sort. Testing Input Format The first line contains 'T' denoting the no. of test cases. Next T lines each contain a number 'n' denoting the numbe… Arrays | Easy | Ready | 30 pts 4 company tags | |
Given an array, sort it using quicksort. Testing Input Format The first line contains 'T' denoting the no. of test cases. Next T lines each contain a number 'n' denoting the number… Arrays | Easy | Ready | 30 pts 4 company tags | |
Given an array of numbers, return an array that contains the squares of all the numbers in non-decreasing order. Example Array: [6, -8, 3, -1, 4] Answer: [1, 9, 16, 36, 64] Testing… Arrays | Easy | Ready | 30 pts 2 company tags | |
Given an array A , find the maximum number of consecutive 1 s in the array. Examples A: [1, 1, 3, 2, 3, 1, 1, 1] Max consecutive 1s: 3 Testing Input Format First line contains an i… Arrays | Easy | Ready | 30 pts 2 company tags | |
An Arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. Given an unsorted array, find if … Arrays | Easy | Ready | 30 pts No company tags | |
A subarray is a part of an array including one or more contiguous/adjacent elements. Example Array: [1, 2, 3, 4, 5] Subarrays: [1] [2] [3] [4] [5] [1, 2] [2, 3] [3, 4] [4, 5] [1, 2… Arrays | Easy | Ready | 30 pts 4 company tags | |
The triangle below is known as Pascal’s triangle. In this triangle, the value at a position is equal to the sum of values of the 2 elements just above it. Examples The 2 nd e… Arrays | Easy | Ready | 30 pts 2 company tags | |
Given a matrix, if any of the cells in the matrix is 0 , set all the elements in its row and column to 0 . Examples 1 1 1 1 0 1 1 0 1 => 0 0 0 1 1 1 1 0 1 0 1 2 0 0 0 3 4 5 =>… Arrays | Medium | Ready | 50 pts 2 company tags | |
Given a matrix, rotate the matrix 90 degrees clockwise. Examples Matrix: 1 2 3 4 5 6 7 8 9 After rotation: 7 4 1 8 5 2 9 6 3 Matrix: 1 2 3 4 5 6 After rotation: 5 3 1 6 4 2 Testing… Arrays | Medium | Ready | 50 pts 3 company tags | |
Given a number, let’s say 10. Can you tell all the divisors of the number? For 10, there are 4 divisors (1, 2, 5 & 10). Let’s take 5, it has 2 divisors (1 & 5).… ArraysHashingMath & Bit Manipulation | Medium | Ready | 50 pts 2 company tags | |
Given a list of intervals, merge them to get a list of non-overlapping intervals. interval i = [start i , end i ] Example: Intervals: [[1, 2], [2, 3], [1, 4], [5, 6]] [1, 2] and [2… Arrays | Medium | Ready | 50 pts 2 company tags | |
Given a list of numbers below: 4, 3, 6, 4, 1 What is the largest element in the list? → 6 What is the 3rd largest element in the list? → 4 Given a list of numbers, find t… Arrays | Medium | Ready | 50 pts 1 company | |
Given an array, rearrange it to its next greater permutation. Do it in-place with extra constant memory only. Do not use any library function for the next permutation. Example Arra… Arrays | Hard | Ready | 80 pts 2 company tags | |
The inversion count of an array denotes how far is the array from being sorted. If the array is sorted, inversion count is 0. If the array is sorted in reverse order, the inversion… Arrays | Medium | Ready | 50 pts 3 company tags | |
Given a sorted array and a number key , return whether the key is present in the array or not. Expected Time Complexity: O(log n) Examples Array: [1, 2, 3, 3, 3, 4, 4, 5] Number: 2… Searching | Easy | Ready | 30 pts No company tags | |
Given a sorted array and a number key , find the index of the first and last occurrence of the key in the array. If the key is not present, return [-1, -1] . Expected Time Complexi… Searching | Easy | Ready | 30 pts 1 company | |
Given a sorted array of integers, find the number of negative numbers. Expected Time Complexity: O(log n) Examples Array: [-5, -3, -2, 3, 4, 6, 7, 8] Answer: 3 Array: [0, 1, 2, 3, … Searching | Easy | Ready | 30 pts No company tags | |
Given a sorted array and a number key , find the smallest array element which is greater than the key. If the key is greater than or equal to the largest element then return the ke… Searching | Easy | Ready | 30 pts No company tags | |
Given a sorted array containing distinct integers and a number 'key', find the index of the key in the array. If the key is not present, return the index at which it would be inser… Searching | Easy | Ready | 30 pts No company tags | |
Given a positive integer num , write a function that returns true if num is a perfect square else false . Note: Do not use the in-built methods to calculate square root or power. E… Searching | Easy | Ready | 30 pts 1 company | |
You are given a list of unique integers which are sorted but rotated at some pivot. You are also given a target value and you have to find its index in the list. If it is not prese… Searching | Medium | Ready | 50 pts 2 company tags | |
Given a sorted list of numbers in which all elements appear twice except one element that appears only once, find the number that appears only once. Example: 1, 1, 2, 3, 3, 4, 4 He… SearchingHashing | Medium | Ready | 50 pts 1 company | |
Given a non-negative integer ' n ', compute and return the square root of 'n'. If n is not a perfect square, return the floor of the result. Note: Do not use the in-built methods t… Searching | Easy | Ready | 30 pts 1 company | |
Given a matrix, check if the matrix contains a given key. The matrix has the following properties: Integer in each row is arranged in non-decreasing order from left to right. The f… Searching | Medium | Ready | 50 pts 1 company | |
Given an n*m matrix which is sorted row-wise, you need to find the median of the matrix. Median of a group of numbers is the middle element after they are sorted. Both n and m are … Searching | Medium | Ready | 50 pts 1 company | |
Given an array and a number k, remove all occurrences of k from the array (in-place). Return the number of elements 'remainingSize' left after removing k. Note that removing the oc… Two Pointers | Easy | Ready | 30 pts No company tags | |
Given a sorted array, check if there exist two numbers whose sum is zero. Example A: [-3, 1, 3, 4] Answer: true A: [-2, 1, 3, 4] Answer: false Testing Input Format The first line c… Two Pointers | Easy | Ready | 30 pts No company tags | |
Given two sorted arrays A and B , find the merged sorted array C by merging A and B . Example: A: [1, 2, 3, 4, 4] B: [2, 4, 5, 5] C: [1, 2, 2, 3, 4, 4, 4, 5, 5] Testing Input Forma… ArraysTwo Pointers | Easy | Ready | 30 pts 4 company tags | |
Given an array and a number k, find the sum of all the subarrays of size k. Example Array: [3, 5, 6, 2, 4, 7, 8] k: 3 Here, the subarrays of size k and their sum are: [3 5 6] =>… Two Pointers | Easy | Ready | 30 pts No company tags | |
Given a sorted array A , find the size of array A after removing the duplicate elements. Examples: A: [1 2 3 3 3 4 5 5] Size of A after removing duplicate elements: 5 Testing Input… Two Pointers | Easy | Ready | 30 pts 4 company tags | |
Given an array A , find all unique triplets in the array whose sum is equal to zero. Example: A: [1, 1, 0, -1, -2] Triplets: [ [-2, 1, 1], [-1, 0, 1] ] Note: Each triplet should be… HashingTwo Pointers | Medium | Ready | 50 pts 3 company tags | |
Given a sorted array A of size n and a number k , return the number of unique pairs which have a difference of k . |arr[i] - arr[j]| = k where i < j Example A: [1, 3, 5, 7, 10] … Two Pointers | Medium | Ready | 50 pts 2 company tags | |
Given two sorted arrays A and B , and another value k , print the k th element of the resultant sorted array. Example A: [1, 2, 3, 4, 5, 6] B: [3, 4, 4, 5, 6, 6] Result: [1, 2, 3, … Two Pointers | Medium | Ready | 50 pts 2 company tags | |
Given 2 sorted arrays, return the intersection of both the arrays. The intersection of 2 arrays means all the elements which are present in both. Example Array 1: [1, 3, 4, 5, 5, 6… Two Pointers | Easy | Ready | 30 pts 2 company tags | |
Sort an array A where each of the elements belong to the set: {0, 1, 2} . Expected Time Complexity: O(n) Try to solve it without storing the count of 0s, 1s and 2s. Example: A: [2,… Two Pointers | Medium | Ready | 50 pts 3 company tags | |
No description available yet. Dynamic ProgrammingStacks & QueuesTwo Pointers | Unrated | Ready | 80 pts 4 company tags | |
Given an array and a number k, find the sum of the subarray that has the maximum sum among all the subarrays of size k. Example Array: [3, 5, 6, 2, 4, 7, 8] k: 3 Here, the subarray… Two Pointers | Easy | Ready | 30 pts 4 company tags | |
Given a string s and a number k, find the number of vowels in every substring of size k. Vowels: ['a', 'e', 'i', 'o', 'u'] Example String: "workattech" k: 3 Here, the substrings of… Two Pointers | Medium | Ready | 50 pts No company tags | |
Given a string s and a number k, find the maximum number of vowels in any substring of size k. Vowels: ['a', 'e', 'i', 'o', 'u'] Example String: "workaattech" k: 3 Here, the substr… Two Pointers | Medium | Ready | 50 pts 1 company | |
Given a Linked List, print all its nodes. Example List: 1→3→4→7 Print: 1 3 4 7 Note: Each node should be separated by a space. Do not print new line anywhere. The main function wil… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a Linked List, return an array containing the nodes of the list in the same order. Example List: 1→3→4→7 Array: [1 3 4 7] Testing Input Format The first line contains ‘T’ den… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a Linked List, print it in reverse direction using recursion. Note: Do not reverse the list. Example List: 1→3→4→7 Print: 7 4 3 1 Note: Each node should be separated by a spa… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a Linked List, find the element at the kth position. Example List: 1→3→4→7 k: 2 Answer: 3 Testing Input Format The first line contains ‘T’ denoting the number of independent … Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a Linked List, an integer k and an element, add that element at the kth position of the linked list. Example List: 1→3→4→7 k: 2 Element: 5 Result: 1→5→3→4→7 Testing Input For… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a Linked List and an integer k, remove the element at the kth position of the linked list. Example List: 1→3→4→7 k: 2 Result: 1→4→7 Testing Input Format The first line contai… Linked Lists | Easy | Ready | 30 pts 1 company | |
Given two Linked Lists, append second Linked List to end of first Linked List and return the first list. Example List 1: 1→3→4→7 List 2: 6→2→5 Result: 1→3→4→7→6→2→5 Testing Input F… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a linked list, reverse it. Example: Input: 1→2→3→4→NULL Output: 4→3→2→1→NULL Testing Input Format The first line contains … Linked Lists | Easy | Ready | 30 pts 4 company tags | |
Given a linked list and a key, remove all occurrences of the key from the Linked List. Return the head of the resultant list. Example Linked List: 1→2→3→2→4→7→2 Key: 2 After remova… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a linked list, find the middle element and print its value. If the list has even number of elements, print the first of the two middle elements. Examples: List: 1→8&rarr… Linked Lists | Easy | Ready | 30 pts 4 company tags | |
Given two sorted linked lists, merge them inplace to produce a singular sorted linked list. Example: A: 2→3→7 B: 1→4→5 Resultant list, after merging A and B: C:… Linked Lists | Easy | Ready | 30 pts 4 company tags | |
Delete a given node from a singly-linked list. You do not have access to the head of the list. Also, the node to be deleted is not the tail of the linked list. Example 1: 1→2&… Linked Lists | Easy | Ready | 30 pts No company tags | |
Given a non-negative number represented as a linked list, determine whether it is a palindrome or not. Example 1: Number : 1234 Linked list : 1→2→3→4 Result : Not a … Linked Lists | Easy | Ready | 30 pts 4 company tags | |
Given two linked lists, find the node at which they intersect. Here the linked lists A and B intersect at C1. If the two lists do not intersect, return null . Testing Input Format … Linked Lists | Easy | Ready | 30 pts 4 company tags | |
Given a sorted linked list, remove all duplicates from the Linked List. After the operation, every element should appear only once. Do not change the order of the linked list. Exam… Linked Lists | Easy | Ready | 30 pts 2 company tags | |
Given a sorted linked list, remove all elements that have duplicates in the Linked List. After the operation, only those elements should be there which were unique in the original … Linked Lists | Medium | Ready | 50 pts 2 company tags |