Check duplicate parenthesis in an expression
A valid mathematical expression can also have duplicate parenthesis as shown below: ((a+b)) (((a+(b)))+(c+d)) Write code to find if an expression has duplicate parenthesis. You may assume that expression does not have any white spaces.
Next greater element
Print Next Greater Element for every element in the array. The Next greater Element of element x is first greater element on its right side. Elements for which no greater element exist, next greater element is -1. Example: – For any array, rightmost element always has next greater element as -1. – All elements of […]
Introducing Graph Data Structure with Adjacency matrix implementation
Binary tree is a specialization of Graph data structure. Node in a Graph is called a Vertex and the connection between two vertices is called an Edge. If we use this terminology, A Binary tree edge is only from a parent to its (at the most two) children. In Graph, any vertex (Node) can connect […]
Recursive implementation of Insertion Sort
We discussed Insertion sort in detail earlier. This post shows the recursive implementation of Insertion Sort.
Count frequency of a number in a sorted array
Given a sorted array of numbers and a number x, count the number of occurrences of x in the array. Input: int arr[] = {1, 3, 3, 4, 4 ,5, 5, 5, 7, 8, 8}; int x = 5; Output: 3
Counting Sort
It is used when there are few unique elements in an array. Counting sort takes O(n+k) time in the worst case, where n is number of elements and all the elements are in the range 1 to k (both inclusive).
Generic pointers in C language
Generic programming, loosely means that the code we have written is type-independent. It is a larger topic, macros in C language also comes under generic programming. In this post we are only discussing generic pointers.
Add sum of all previous elements in array (DPFCI_1.2)
This question is from exercise in my book Dynamic Programming for Coding Interviews (Question: 1.2, Page-5) Question: Given an array, arr of integers, write a recursive function that add sum of all the previous numbers to each index of the array. For example, if the input array is {1, 2, 3, 4, 5, 6} then […]
Find minimum of 3 numbers without using comparator operator
How will you find minimum of three integers without using any comparison operator ?
Merge two sorted arrays
Given two sorted arrays of size m and n respectively. Also given an empty third array of size (m+n). write code to merge the two arrays and store the result in the third array. INPUT ARRAYS: a = {1, 4, 5, 9} b = {0, 2, 3, 7, 15, 29} OUTPUT: c = {0, 1, […]