Adap.tv Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

while(str[l]!='\0')
{
for(int i=0;i<n;i++)
{
for(int j=0;j<=n-i-1;j++)
cout<<" ";
for(j=0;j<=i;j++)
{
cout<<str[l++]<<" ";
}
cout<<"\n";
}}}
this will print your name in pascal triangle!

- mahima September 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Please restate the problem. The way it's stated is something highschool kids do.

- bigphatkdawg September 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

At first glance I thought this was a simple problem.... then I tried to code it. Took me a little mental gymnastics, but I figured it out. Here was my process for figuring it out:

The pascal triangle is based on the formula n(n-1)/2 which gives the following pyramid:

1
23
456
etc...

So, this means we need to print the name 'anony' as:

a
no
ny-

I am using a '-' to fill in empty spaces for the last line as not every name is equivalent to a triangular number. Then I reasoned through printing out each line, and what the start and end point of each line should be. This led me to look at the DIFFERENCE between the starting points on each line, as well as the ending points on each line. This gave me the following breakdown:

Start points: 1 2 4 7 11
Start Dif: 1 2 3 4
End points: 1 3 6 10 15
End Dif: 2 3 4 5

So my start point increases by a linear incremental amount each iteration. My end point also increases by a linear incremental amount on each iteration, but by an amount that is 1 larger than the start difference.

For simplification, we handle the single case as a stand alone so we don't have to fight with arrays being 0 indexed and how that can create confusion with our algorithm. That being said, here is my algorithm for this process:

1. Declare a counter, start, and end and set all to 0
2. Print the first character and move to the next line
3. While end is less than the length of the name, do steps 4-8
4. Increment count by 1
5. Increment start by count
6. Increment end by count + 1
7. Loop through and print all chars from start to end (inclusive), if you go past the end of the name array, then print a '-' to finish the triangle (you could also return early and leave a pyramid with missing blocks in its foundation)
8. Move to next line and return to step 3

Below is my sample code along with a sample output:

String name = "WhatALongName";
int start = 0, count = 0, end = 0;

System.out.println(name.charAt(0));

while(end < name.length()){
    count++;
    start += count;
    end += (count + 1);

    for(int i = start; i <= end; i++){
        if(i < name.length()){
            System.out.print(name.charAt(i));
        }
        else{
            System.out.print("-");
        }
    }

    System.out.println();
}

Output:
W
ha
tAL
ongN
ame--

- masterjaso September 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Here it s a complete code ..just copy this and paste in browxy

Many thanx to - masterjaso for ths good code,,,,

import java.io.*;
public class Stringex{
public static void main(String args[]){

String name = "SachinTendulkar";
int start = 0, count = 0, end = 0;

System.out.println(name.charAt(0));

while(end < name.length()){
count++;
start += count;
end += (count + 1);

for(int i = start; i <= end; i++){
if(i < name.length()){
System.out.print(name.charAt(i));
}
else{
System.out.print("-");
}
}

System.out.println();
}}}


output:
S
ac
hin
Tend
ulkar
------

- Mikki September 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

OK, I think this is a pretty simple problem, I've run it on Visual Studio 2010
My code is shown below:

void printPascalTrangle(string str)
{
int length = str.size();
int lineCount = 1;
int i = 0;

/* output the string at first */
for (string::iterator it = str.begin(); it != str.end(); it ++)
cout << *it;
cout << endl;

/* print pascal trangle */
while (length > 0)
{
for (int j = 0; j < lineCount; j ++)
{
cout << str.at(i);
if (++ i == str.size() - 1)
break;
}
cout << endl;

lineCount ++;
length -= lineCount;
}
}

- Tyler September 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey Anony .. I am about to appear for Adap.tv interviews . Please list all questions asked by them . Also, do they only grill candidates on Algorithms or do they ask other stuff as well?

- Ankur September 19, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More