Find a pair with the given sum in an array
Given an unsorted integer array, find a pair with the given sum in it.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven an unsorted integer array, find a pair with the given sum in it.
Given an array containing only 0’s, 1’s, and 2’s, sort it in linear time and using constant space.
Given a binary array, sort it in linear time and constant space. The output should print all zeros followed by all ones.
Given an unsorted integer array that represents binary search tree keys, construct a height-balanced BST from it.
Write a function that takes two lists, each of which is sorted in increasing order, and merges the two into one list, which is in decreasing order, and returns it. In other words, merge two sorted linked lists from their end.
Given a linked list, sort it using the merge sort algorithm. Merge sort is an efficient, general-purpose sorting algorithm that produces a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output.
Given a string sorted in ascending order, find all lexicographically next permutations of it. The words are arranged in the same order in the lexicographic order as they are presumed to appear in a dictionary.
Given a string, find all palindromic permutations of it… We know that the left and right half of a palindrome contains the same set of characters, so any palindromic permutations of a string are only possible if each character’s frequency in the string is even.
Given a list of words, efficiently group all anagrams. The two strings, X and Y, are anagrams if by rearranging X’s letters, we can get Y using all the original letters of X exactly once.
Given an array of positive and negative integers, segregate them in linear time and constant space. The output should print all negative numbers followed by all positive numbers.
Given an array, find the total number of inversions of it. If (i < j) and (A[i] > A[j]), then pair (i, j) is called an inversion of an array A. We need to count all such pairs in the array.
Given two arrays, reorder elements of the first array by the order of elements defined by the second array. The elements that are not present in the second array but present in the first array should be appended at the end sorted.