A sorted array is given, write a program to remove duplicates from sorted array. We need to remove repeated elements such that there is a single occurrence of each element and return the length of array containing unique elements. Note: This is an excellent problem to learn fast and slow pointers approach. We have discussed two O(n) time in place solutions.
Given an array X of integers, find the maximum parity index. The parity index is the maximum index difference between two elements (X[i], X[j]) such that, j > i and X[j] > X[i]. In other words, we need to find maximum j - i such that j > i and X[j] > X[i]. Note: This is an excellent problem to learn problem solving using sorting and two pointers approaches
Given n non-negative integers representing an elevation map where the width of each bar is 1. Write a program to compute how much water it can trap after raining. This is a famous interview problem to learn time and space complexity optimization using various approaches. Two pointers approach provides an efficient solution using O(n) time and O(1) space.
Given an array X of n integers, write a program to find product array such that product[i] is equal to product of all array elements except X[i]. We need to solve this problem without using division operations. Note: This is an excellent product array puzzle to learn time complexity optimization using prefix array and a single loop.
Write a program to find equilibrium index of an array. An array's equilibrium index is an index such that the sum of elements at lower indexes equals the sum of elements at higher indexes. Note: This is an excellent coding question to learn time and space complexity optimization using prefix array and a single loop using variables.
Given an n x n 2D matrix, write a program to rotate the matrix by 90 degrees in anticlockwise direction. We should rotate matrix 90 degrees without using extra space. In other words, we have to perform rotation by modifying 2D matrix directly. Note: This is an excellent problem to learn problem-solving using nested loops and transpose of a matrix.
Given an array X of n elements filled with several integers, some of them being zeroes, write a program to move all the zeros to the end. We need to preserve the relative order of non-zero elements and solve this problem in place using O(n) time complexity. Note: This is an excellent problem to learn problem solving using two pointers approach.
Subscribe to get weekly content on data structure and algorithms, machine learning, system design and oops.