## First element occurring k times in an array

We have given a number ‘k’ and an integer array. The problem “First element occurring k times in an array” says to find out the first element in the array which occurs exactly k times in an array. If there is no element in the array which occurs k times …

## Golomb sequence

Problem Statement   The problem “Golomb sequence” states that you are given an input integer n and you need to find all the elements of Golomb sequence until nth element. Example   n = 8 1 2 2 3 3 4 4 4 Explanation The first 8 terms of the Golomb sequence …

## Find Index of Closing Bracket for a Given Opening Bracket in an Expression

Problem Statement   Given a string s of length/size n and an integer value representing the index of an opening square bracket. Find index of closing bracket for a given opening bracket in an expression. Example   s = “[ABC]” index = 0 8 s = “[C-[D]]” index = 3 5 s …

## Iterative Method to find Height of Binary Tree

Problem Statement   The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples   Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree   The height of a tree …

## Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’

Problem Statement   The problem ” Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ ” states that you have an “n” sized array containing integers. The numbers in the array are in a range of 0 to n-1. The problem statement asks to rearrange the array in …

## Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest

Problem Statement   Suppose you have an integer array. The problem “Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest, ..” asks to rearrange the array in such a way that the smallest number comes first and then the largest number, then second smallest and then the second …

## Find distinct elements common to all rows of a matrix

Problem Statement   We are given a matrix of all the integers. The problem “Find distinct elements common to all rows of a matrix” asks to find out all the possible distinct elements but common in each of the rows present in a matrix. Example   arr[]={ {11, 12, 3, 10}, {11, …

## Check if Two Expressions With Brackets are Same

Given two strings s1 and s2 representing expressions containing addition operator, subtraction operator, lowercase alphabets, and parenthesis. Check if two expressions with brackets are the same. Example   Input  s1 = “-(a+b+c)” s2 = “-a-b-c” Output  Yes Input  s1 = “a-b-(c-d)” s2 = “a-b-c-d” Output No Algorithm to Check if Two …

## Check for Balanced Parentheses in an Expression

Given a string s of length n. Check whether there is a closing parenthesis for every opening parentheses i.e. if all the parentheses are balanced. In other words, we can also say that, if we have a ‘}’, ‘)’ and ‘]’ for every ‘{‘, ‘(‘ and ‘[‘ respectively, the expression …

## Balanced Expression with Replacement

In Balanced Expression with Replacement problem we have given a string s containing parenthesis i.e. ‘(‘, ‘)’, ‘[‘, ‘]’, ‘{‘, ‘}’. The string also contains x at some places as a replacement of parenthesis. Check if the string can be converted into an expression with valid parenthesis after replacing all …