Tag Archives: DSA

Easy Multi-Layered Calculation

Count the number of even/odd results after performing a series of calculation on a range of numbers. Given that: Each layer of calculation have two numbers (say a and b) associated with it. For each input x, y = ax + b is calculated. The result of layer i, i.e y, becomes input for layer i+1. The range… 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 »