X
Submit Question

Google  Questions

View By:

Q1 Reverse characters of each word in a sentence

Given a linked list containing characters that form a string such as

--------- "my career stack" ---------
Reverse the characters of each word, keeping the order of the words same such that the output will be

--------- "ym reerac kcats" ---------

Linked List  |  Level - 3

Answer Write Code Visit Question Page

Q2 Minimum cost for painting a row houses in three different colors

There are N houses in a row. Each house can be painted in either Red, Green or Blue color. The cost of coloring each house in each of the colors is different.

Find the color of each house such that no two adjacent house have the same color and the total cost of coloring all the houses is minimum.

Update: The question intends to state that cost of painting any house in any color is different, so if cost of painting House 1 in Red is say, X then the cost of painting House 2 in red will some other value Y. It can be considered each house has different dimensions and hence cost of painting in each color is different, and the cost of paint for each house also varies

Puzzles  |  Level - 2

Answer Write Code Visit Question Page

Q3 How to convert singly linked list to binary search tree?

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

Linked List  |  Level - 2

Answer Write Code Visit Question Page

Q4 Find the intervals from a set of intervals in which a given point lies

Given a set of intervals such as (10,20), (15,25), (28,40), (50,70), (0,9) (60,90) and build a data structure. Query the data structure for point x, and it find out all the intervals that contain this point x.

Trees and Graphs  |  Level - 3

Answer Write Code Visit Question Page

Q5 Find elements that sum to a given value in a balanced BST

Find two elements in balanced BST which sums to a given a value. Constraints Time O(n) and space O(logn).
          6
     3         8

1    4    7      12

sum = 16 o/p should be 4 and 12

Algorithm  |  Level - 2

Answer Write Code Visit Question Page

Q6 Number of occurrences of a number in a sorted array.

Given a sorted array, find the number of occurrences of an element in the array. Give a O(logn) time solution.

Arrays  |  Level - 2

Answer Write Code Visit Question Page

Q7 Given a preorder and a postorder traversal, construct the tree.

Given a preorder and postorder traversal of a Binary Tree, construct the tree using these two traversals.

Trees and Graphs  |  Level - 3

Answer Write Code Visit Question Page

Q8 Validate a Binary Search Tree

Validate a Binary Search Tree, meaning given a binary tree find out whether it is a BST or not.

Trees and Graphs  |  Level - 3

Answer Write Code Visit Question Page

Q9 What is the minimum number of comparisons required to find the largest and the second largest elements in an array

What is the minimum number of comparisons required to find out the largest and the second largest elements in an array.

If it makes your life easier you can use extra space. But try to keep it less.

Algorithm  |  Level - 3

Answer Write Code Visit Question Page

Q10 Finding non-anagramic strings in a list

Given a list of strings, find out the number of strings which do not have an anagram present in the list.

String Manipulation  |  Level - 3

Answer Write Code Visit Question Page