# Array

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.

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 […]

Given an array of numbers find the maximum XOR value of two numbers in the array. Input Array = {12, 15, 5, 1, 7, 9, 8, 6, 10, 13}; Output = 15 (XOR of 5 and 10) 5 = 0101 10 = 1010 ——— XOR = 1111

Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ in them). For example consider the below matrix: A – – – B – – – C All characters are unique. Set character on all empty cells in such a […]

Given a matrix of integers of order M*N and coordinates of a rectangular region in the matrix, write code to find the sum of all the elements in that rectangular region. For example, if the input matrix is And co-ordinated given are (3,4) and (6, 8), then they represent the below rectangular region whose Sum […]

Given a row (linear), two blocks are placed at each end and there are n empty positions between then. If ‘B’ represent block and n = 9 then the row looks like below: B _ _ _ _ _ _ _ _ _ B One blocks can be placed on each empty position. k blocks […]

Given a number N given in the form of array, with each index storing one digit of the number. Write code to change the number to the greatest number less than N, such that digits of that number are in non-decreasing order. For example: INPUT ARRAY: {1, 4, 3} (representing number 143) OUTPUT : 139 […]

Given a string of bits and a number k. In one flip, you can toggle k consecutive characters, how many flips are required to change the entire string to all ones. For example Input String: 0000110000 k: 3 OUTPUT: 4 Following are the four flips: FLIP-1: 1110110000 FLIP-2: 1110110111 FLIP-3: 1111000111 FLIP-4: 1111111111 If it is not possible […]

Given a string, print the variation of string as shown below Input String: ‘hat’ Replace one character with numeric one(‘1’): ‘1at‘, ‘h1t‘, ‘ha1‘ Replace two characters with ‘1’ each: ‘11t‘, ‘h11‘, ‘1a1‘ Replace three characters with ‘1’ each: ‘111‘ In all the strings above, wherever the numeric characters are consecutive, add them. So ’11t’ will become ‘2t’, Similarly ‘111’ […]

Given two arrays of integers, write a code to check if one is permutation (arranging the same numbers differently) of elements present in the other. For example, the below two arrays are permutations of each other: int a[5] = {1, 2, 3, 4, 5}; int b[5] = {2, 1, 4, 5, 3};