Posts

Showing posts with the label LinkedIn

Getting the total covered length given the interval

Problem Write the program that takes the series of intervals and returns a total length covered by the added intervals.  If several intervals intersect, the intersection should be counted only once.  Example:  addInterval(3, 6)  addInterval(8, 9)  addInterval(1, 5)  getTotalCoveredLength() =>; 6  I.e. [1,5) and [3,6) intersect and give a total covered interval [1,6).       [1,6) and [8,9) don't intersect, so the total covered length is a sum of both intervals, that is 5+1=6.                     ______                                        _           _________          0  1  2  3  4  5  6  7  8  9  10      Now, implement the follow...

Planting flowers with no adjacent flower plots

Image
Problem Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represented as an array containing booleans), return if a given number of new flowers can be planted in it without violating the no-adjacent-flowers rule  Sample inputs  Input: 1,0,0,0,0,0,1,0,0  3 => true  4 => false  Input: 1,0,0,1,0,0,1,0,0  1 => true  2 => false  input: 0  1 => true  2 => false  public boolean canPlaceFlowers(List flowerbed, int numberToPlace) {  // Implementation here  }

Evaluating the reverse polish notation

Problem Given the list of strings consisting of the asthmatic equation expressed in the Reverse Polish notation. Write the program that evaluates the equation and returns the result. Example:     For { "4" , "1" , "+" , "2.5" , "*" }, output =12.5     { "5" ,  "80" , "40" , "/" , "+" } = 7

Counting rooms problem

You are the event coordinator and want to find out how many event rooms you will need to accommodate the event schedules. Given the event schedule as follows: {8-9}, {9-10}, {8-10}, {11,14}, {14,15},{13,16}, {10, 13},{10,12}, {13,15} Event time can not overlap unless one event ends in the same hour as the other event start. e.g. event 1 {2,3} and even 2 {3-4} can be held in the same event room. Your program should calculate how many rooms are necessary.

Calculating the sum of each level in the tree

Question: Given a binary tree with nodes containing integer values. Your algorithm should calculate the sum of values in each depth and returns sums. Example:           1          /   \        2     3       /  \   /  \     4   5 1    2 Output:  1, 5, 12

Palindrome problem

Problem The palindrome problem is another classic algorithm question. Given the sentence, write the code checking if the sentence is a palindrome. Any non-alphabet characters should be ignored. Examples: A car, a man, a maraca. A dog, a plan, a canal: pagoda. A dog! A panic in a pagoda! A lad named E. Mandala A man, a plan, a canal: Panama.