Interview Question


Team: Subex
Country: India
Interview Type: Written Test




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

vector<string> lines;
string newString;
int max = 0;
while (cin >> newString)
{
	if (max < newString.length())
	{
		max = newString.length();
	}
        lines.push_back(newString);
}

for (int i = 0; i <  max; ++i)
{
	for (int j = 0; j < lines.size(); ++j)
	{
		if (i < lines[j].length())
		{
			cout << lines[i];
		}
	}
	count << endl;
}

- coding.arya July 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let the text file name be text.dat.                 
    void transp_matrix(FILE* fp,int rows,int col)
    {
       int j=0;
      char **p;
      p=malloc(rows*sizeof(char*));
        for(int i=0;i<rows;i++)
          {
            p[i]=malloc(col*sizeof(char));
           while(int ch=fgetc(fp) && ch!='\n')
              {
                 p[i][j]=ch;
                   j++;
              }
            }
            for(i=0;i<rows;i++)
              for(j=0;j<col;j++)
               {
                 p[j][i]=p[i][j];
               }
          


    }

- manish27.p July 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String s1="asd";
String s2="bte";
String s3="cu";
char[] c1=s1.toCharArray();
char[] c2=s2.toCharArray();
char[] c3=s3.toCharArray();
Object[] o1={c1[0],c2[0],c3[0]};
Object[] o2={c1[1],c2[1],c3[1]};
Object[] o3={c1[2],c2[2]};

for(Object p1:o1)
{
System.out.print(p1);
}
System.out.println();
for(Object p2:o2)
{
System.out.print(p2);
}
System.out.println();
for(Object p3:o3)
{
System.out.print(p3);
}

- Anonymous August 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

very nice dude,,,,really thank u..any one new 2 ths ..just copy the code as i mentioned below and paste,run it in this. browxy.com

import java.io.*;

public class Check
{
public static void main(String args[])
{
String s1="asd";
String s2="bte";
String s3="cu";
char[] c1=s1.toCharArray();
char[] c2=s2.toCharArray();
char[] c3=s3.toCharArray();
Object[] o1={c1[0],c2[0],c3[0]};
Object[] o2={c1[1],c2[1],c3[1]};
Object[] o3={c1[2],c2[2]};

for(Object p1:o1)
{
System.out.print(p1);
}
System.out.println();
for(Object p2:o2)
{
System.out.print(p2);
}
System.out.println();
for(Object p3:o3)
{
System.out.print(p3);
}}
}

- subbu August 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

String s1="asd";
String s2="bte";
String s3="cu";
char[] c1=s1.toCharArray();
char[] c2=s2.toCharArray();
char[] c3=s3.toCharArray();
int size = Math.MAX(c1.length,c2.length,c3.length)
for(int i=0;i<size;i++){
if(c1.length>i){
System.out.print(c1[i]);
}
if(c2.length>i){
System.out.print(c2[i]);
}
if(c3.length>i){
System.out.print(c3[i]);
}
System.out.println("\n");

}

- Shiva jee August 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have written a program which reads from a file ( size does not matter - tested with 25mb file) and then transposes the whole strings in that file .
input 1) hello
dello
rello
input 2) skydrive
videodrive
store
For input 2 I add space where required and then print ,
$ = space

skydrive$
videodrive
store$$$$
After adding the space I transpose the strings in the file.
#####################################################################

package com.CareerCup;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

public class TransposeStringInFile {

public static void main (String string[]) throws Exception
{
int coloum=0;
int row=0;
FileReader freader=null;
BufferedReader bufferReader=null;
//we read the file line by line and put each line of the file into this arrary as one string
ArrayList <String> LinesInFile = new ArrayList<String>();

try{
File file = new File("C:\\urlFile1.txt");
freader = new FileReader(file);
bufferReader = new BufferedReader(freader);
String temStr;
int strLen;

while( (temStr=bufferReader.readLine())!= null)
{

//we try to find the longest line so that our charArray will have that long coloum
strLen = temStr.length();
if(strLen > coloum)
{
coloum=temStr.length();
}
//add each line in the file to the arrayList
LinesInFile.add(temStr);
}

//the rows are nothing but the number of lines in a file
row = LinesInFile.size();

//we have calculated the max length of a line ( string) in the file so the charArray will be with that dimensiton = row X colum matrix
//where row is number of lines in the file . Coloum is longest line in the file .
char [][] charactersInFile = new char[row][coloum];


for(int i=0; i< row; i++)
{
char tempCh[] = LinesInFile.get(i).toCharArray();
int ListCharLen= tempCh.length;
if( ListCharLen < coloum)
{

//this method is used to padd the space when its not a square matrix if the input is like
// one
// seven
// two
//Then we create an arry and padd the space where reqired here ---> $ = space
// one$$
// seven
// two$$

paddSpace(ListCharLen , tempCh ,charactersInFile[i] ,coloum );

}
else
charactersInFile[i]=tempCh;

}

for(int i=0;i<coloum;i++)
{
for(int j=0;j<row;j++)
{
System.out.print(charactersInFile[j][i]);

}
System.out.print("\n");
}
}
finally
{
bufferReader.close();
freader.close();

}

}
//this method is used to padd the space when its not a square matrix if the input is like
// one
// seven
// two
//Then we create an arry and padd the space where reqired here ---> $ = space
// one$$
// seven
// two$$
static void paddSpace(int ListCharLen , char tempCh[] , char OriginalCharactersInFile[] , int maxLen )
{
int i=0;

for( ; i<ListCharLen;i++)
{
OriginalCharactersInFile[i]= tempCh[i];
}
//adding space for the left length
int padd = maxLen -ListCharLen;
while(padd != 0)
{
OriginalCharactersInFile[i]= ' ';
i++;
padd--;
}

}

}

- Mahanth Hiremath ( mahanathopensource@gmail.com) August 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

public class FileStringTranspose {

public static void main(String[] args) throws IOException {

File f = new File("Data.txt");

BufferedReader br = new BufferedReader(new FileReader(f));

List<Integer> sizeList = new LinkedList<Integer>();

List<String> lines = new LinkedList<String>();

String line = null;

//Read from the file and add line to the List.
while ((line = br.readLine()) != null) {
lines.add(line);
sizeList.add(line.length());
}

//Sort the sizeList to get the max length of a line at the last index.
Collections.sort(sizeList);

//Get the value at the last index of the Size List
int largestCharPosition = sizeList.get(sizeList.size() - 1);

int j = 0;
while(j < largestCharPosition) {
for(int i = 0; i < lines.size(); i++) {
int length = lines.get(i).length();
if(length > j) {
System.out.print(lines.get(i).charAt(j));
}
}
System.out.println();
j++;
}
}
}

- 2010prashant September 11, 2013 | Flag


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