## Forum Posts

- 6 Answers
**How to Solve This Type of Problem..**There is a room where boxes are stacked. If the room is rotated 90 degrees to the

- dhakadkush December 16, 2015

right, boxes will fall, affected by gravity. Finds out a box which will have the longest ‘fall distance’, and

output the value of the longest ‘fall distance.

like there are 26 boxes in total (7 + 4 + 2 + 6 + 7 = 26). After rotating, gravity

affects all boxes and final state becomes like the room on the right. Among these 26 boxes, a ‘fall

distance’ of box A is the longest as 7, therefore, return 7.

For reference, a ‘fall distance’ of box B is 6, and a ‘fall distance’ of box C is 1. Gravity begins to apply after rotation is finished.

Boxes are stacked being adjacent to one side of the wall, thus all boxes are located in a two

dimensional plane. There is no box which is stacked apart from the wall. The width of the wall is always 100, and the height of the wall is always 100.

Input

First line contains t, the number of test cases.

t test cases follow. Each test case has 2 lines. First line of each test case is n, the width of the

room.

Next line contains n space separated integers representing the number of boxes in each stack.

1<=t<=10

1<=n<=100

Output

The program should give output in separate line, for each test case

Sample Input

1

9

7 4 2 0 0 6 0 7 0

Sample Output

7| Flag | PURGE - 0 Answers
**Given a set and a pairwise xor set, find the second set?**We take 2 sets of integers to generate a third set with contains the xor of every element in the first set with every element in the second set.

- suyash93 November 23, 2015

Now as a problem we have been given the first set and the third set i.e. the set with xors, and we need to generate the second set.| Flag | PURGE - 0 Answers
**Flipkart Interview Questions- Offcampus**You have been given of stream of integer find out the 1st non repeated integer.

- taniyaag November 22, 2015

example 21235 :here 1st integer would be 1,

123452134 : here the 1st non repeated integer would be 5.

Please let me know the solution to above question.| Flag | PURGE - 0 Answers
**Need Help with recursive time complexities**I am getting a bit confused with verbal (& fast) calculation of time complexities of recursive functions.

- tanmay.ashok.patil November 18, 2015

The substitution method & recursion tree method takes a lot of time and during interviews are not feasible options.

So I need help with fast and verbal calculation of recursive functions.

For eg.

The below method is called recursively.

Inside the method a for loop runs from 1 to n. And for each iteration the recursion is called twice.

How should the Big-Oh should be calculated?

compute(){

if(){

// some base case which terminates the recursion

} else {

for(1 -> n){

compute();

compute();

}

}

}

Thanks For Reading| Flag | PURGE - 1 Answer
**Reverse an array of integers**Is there a better way to reverse an array of integers than the one below. Will using a stack perform better

- Megha Maheshwari November 18, 2015

int [] array = {2,5,7,8,9,10}

int startindex = 0;

int endindex = array.Length -1;

while(startindex < endindex)

{

int temp = array[startindex];

array[startindex] = array[endindex];

array[emdindex] = temp;

startindex++;

endindx--

}

Complexity : O(n/2)| Flag | PURGE - 0 Answers
**Negotiating a Google vs Facebook offer**I am in the lucky position to will be receiving an offer both from Goog and Fb. The companies know about each other. Goog apparently decided not to extend an offer if I don't tell them what's Fb offer first. My other option was to tell them what total compensation I would need to shut the door with Fb without hearing their offer at all. I took time and have not talked to FB yet. What's the rational behind Goog's (questionable) move? What's the best course of actions for me at this point?

- gevhar November 14, 2015| Flag | PURGE - 0 Answers
**How to get callbacks after a long employment gap**I have a BS and MS in Computer Science and due to illness I have been out of work for 5 years. I seem to be on the upswing and have been submitting resumes with no luck.

- lilgeekboy November 05, 2015

I do programming projects when I can as well as pick up new languages(learning elixir right now) to keep in practice. I also work on coding interview and programming contest questions.

The big problem is that my health took a nose dive as I was completing my MS and I only have small internship work and a non-programming consulting gig as work history.

Is there any hope for actually getting an interview and hired or is my degree wasted?| Flag | PURGE - 0 Answers
**Sample Code Practice Problem**Having a bit of trouble identifying why this code is throwing an out of bounds error on line 16. Not entirely sure how to fix it. I think I am overlooking something.

- elisefstorey October 12, 2015

public class sampleCode {

public static void main( String[] moe ) {

int[] larry = new int[moe.length];

for( int i=0; i < moe.length; i++ ) {

larry[i] = Integer.parseInt( moe[i] );

}

int[] curly = null;

if( larry.length <= 10 ) {

curly = path1( larry );

} else

curly = path2( larry );

// PRINT RESULTS

System.out.println( curly[0]+", "+curly[1] );

}

public static int[] path1( int[] foo ) {

for( int i=0; i<foo.length; i++ ) {

for(int j=0; j<foo.length-1; j++) {

if( foo[j] > foo[j+1] ) {

int bar = foo[j];

foo[j] = foo[j+1];

foo[j+1] = bar;

}

}

}

return foo;

}

public static int[] path2( int[] foo ) {

int[] z = null;

if( foo.length > 1 ) {

int bar = foo.length / 2;

int[] a = new int[bar];

int[] b = new int[foo.length - bar];

for( int x=0; x<foo.length; x++ ) {

if( x<bar ) a[x] = foo[x];

else b[x-bar] = foo[x];

}

z = path2b( path2( a ), path2( b ) );

} else {

z = foo;

}

return z;

}

protected static int[] path2b( int[] foo, int[] bar ) {

int i=0;

int j=0;

int x=0;

int[] z = new int[foo.length+bar.length];

while( i<foo.length || j<bar.length ) {

if( i < foo.length && j == bar.length ) {

z[x] = foo[i++];

} else

if( j < bar.length && i == foo.length ) {

z[x] = bar[j++];

} else

if( foo[i] < bar[j] ) {

z[x] = bar[j++];

} else {

z[x] = foo[i++];

}

x++;

}

return z;

}

}| Flag | PURGE - 0 Answers
**Help with booking algorithm question**You are building a small command-line application to calculate hotel availability for a city. Your application reads in two (2) data files, and outputs its answer to STDOUT.

- amusing October 05, 2015

Your application will read in:

· a list of hotels along with how many rooms each contains (in no particular order)

· a list of bookings that have been made (in no particular order)

Your application will then print the list of all hotels which have availability for check-in and check- out date range, if any.

Do not worry about whether a specific room is available in a hotel for the entire booking period without switching rooms: availability is defined as the hotel having at least one (1) available room for each night of the target stay, regardless of whether it's the same room from day to day.

Data Files

hotels.csv

# Name, Rooms

Westin, 10

Best Western, 20

Hilton, 10

...

bookings.csv

# Name, Checkin, Checkout

Hilton, 2015-04-02, 2015-04-03

Hilton, 2015-04-02, 2015-04-04

Westin, 2015-05-01, 2015-05-20| Flag | PURGE - 1 Answer
**PM Interview Question**Need help with the following question, I think I'm overthinking it...

- DCWebDeveloper October 01, 2015

Create an algorithm to increase revenue yield on a CPC advertising page:

- the page has 7 tabs visible when it loads, if a user clicks on one of those tabs, the travel website gets paid a CPC

-The tabs allow the user to enter their search information once (flight search page) and compare search results across multiple sites

- The tabs are CPC advertisers; we get paid each time a user clicks a unique tab per search session (search session is defined as a set of tab results for any origin, destination and date combo)

- For this exercise, please conceptualize an algorithm that delivers the highest revenue yield for the tabbed commerce auction (revenue yield = revenue per search session)

Assumptions:

- Each tab pays a different CPC (no two tabs have the same CPC)

- Not all search sessions contain a tab click; however, the average number of tab clicks per search session is 3

- There is no click (or spend) cap per tab (meaning tabs can receive an infinite number of paid clicks across multiple sessions at a rate of one unique click per session)

| Flag | PURGE - 1 Answer
**QuickSort in Java - using only one loop? Is it possible?**Hello,

- Saurabh September 26, 2015

All the implementations of Quicksort I searched on the internet uses nested loops, one parent loop and then inside 2 loops for each of the pointers, left and right. Given the logic of the quick sort, I was intrigued by the question that why is it not possible to write the QuickSort algorithm using only one while loop, where we push the left and right pointers to their next positions if possible using only the parent while loop?

I tried but it fails. If using only one loop for both pointers isn't possible, I would like to understand why behind it. There should be some logical/mathematical reasoning behind why we need to use separate loops for the left and right pointers?

Here is the code for my faulty attempt:

public class QuickSort {

public static void sort(int[] input){

sortArray(input,0,input.length-1);

}

public static void sortArray(int[] array, int p, int q){

int left, right, pivot;

pivot = p;

left = p+1;

right = q;

//end condition, if only 1 element is there in the array

if(p>=q){

return;

}

boolean leftMoved = false, rightMoved=false;

while(left <= right){

leftMoved = false;

rightMoved=false;

if(left< q && array[left] < array[pivot]){

left ++;

leftMoved = true;

}

if((left < right) && array[right] > array[pivot]){

right --;

rightMoved=true;

}

if(left < right && leftMoved==false && rightMoved==false){

//swap left and right

int temp = array[right];

array[right] = array[left];

array[left] = temp;

if(array[left]==array[right]){

left++;

}

}

}

//swap pivot and left, only if left is less than pivot, if not then it means pivot is already at it's right place.

if(array[pivot] > array[left]){

int temp = array[pivot];

array[pivot] = array[left];

array[left] = temp;

}

//now sort left side array

sortArray(array,p,left-1);

//and right side array

sortArray(array,left+1,q);

}

}| Flag | PURGE - 0 Answers
**Google Route Matching Algo / Architecture - Server Side ( Server Platform &/ DB)**Hi,

- pramod29feb September 22, 2015

I have multiple Google Routes in the form of ployline String or Array of ployline points (sequential latitude & longitude) which has info of source to destination via a path.

I have a location and it's latitude & longitude.

I need to check on the server side which of these google routes pass through this location. If there is space of tolerance in terms of kms it could be .005 KM.

Appreciate any quick help:)| Flag | PURGE - 0 Answers
**Igate vs Wipro**Hi, I have offers from Igate as well as Wipro for an experienced position. I am confused which company to choose from. Igate offer is 1 lakh more than Wipro but money aside, Igate is offering me Tech Lead vs Wipro B2(Sr. Software Eng)

- SwatiManish September 16, 2015

Can someone please help me with this?

Thanks| Flag | PURGE - 1 Answer
**I am looking to learn new algorithmic techniques - need suggestions**I want to prepare mysef for some programming contest. I have been solving few problems based on arrays and loops. I would like to solve more complicated problems based on these area.

- pingkucis September 04, 2015

I would be grateful if you know any good lists of problems that are really crucial and/or teach useful new techniques, as I am stuck momentarily. I have read the results on Google for ACM algorithms and such, so a personal response would be a lot more appreciated :).

Thank you a lot!| Flag | PURGE

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window