Category Archives: Arrays

Lexicographical smallest alternate Array

Given two arrays of element between 0 to N- 1 of length N. Find the lexicographically smallest array c such that for any index i  c[i] = ( a[i] + b[i])%N. To find the lexicographically smallest array we can rearrange the elements of the second array. Example: Input: a[]: {0, 1, 2, 3} b[]: {3, 1, 0, 2} Output:… Read More »

Tricky C++ programs

Programming has never been easier. Even though you may have mastered a particular programming language, there might still be some concepts that may make you dizzy on reading it. This article contains some set of tricky questions which may make you go dizzy. 1. Take a look at this terminated int main (); What will this program do?… Read More »

k-th distinct (non-repeating) element in an Array

Given an integer array arr[] a non negative integer k, print k-th distinct element in an array. The given array may contain duplicates and the output should print k-th distinct element among all elements in the array. If k is more than number of distinct elements, print -1. Examples : Input : arr[] = {1, 2, 1, 3,… Read More »