Techlogix Interview Question for Interns


Country: India
Interview Type: Written Test




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

Simple Java Code:

public class NumbersCharacters {
	public static void main(String[] args) {
		String given = "a4b2c2a3f1g2";
		String[] strArray = given.split("");
		String result = "";
		System.out.println(given.length());

		for (int i = 0; i < strArray.length; i += 2) {
			int limit = Integer.parseInt(strArray[i + 1]);
			System.out.println("limit: " + limit);

			for (int j = 0; j < limit; j++) {

				result += strArray[i];

			}
		}

		System.out.println("Final String: " + result);
	}

- viksidada March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string.h>
using namespace std;

char *Create_String()
{
	char *String, *Temp;
	Temp = new char[256];
	gets(Temp);
	String = new char[strlen(Temp)+1];
	strcpy(String, Temp);
	delete [] Temp;
	return String;
}

void The_Function(char *String)
{
	int Rround_Times;
	char Current_Char;

	for (int i=0 ; String[i] != '\0' ; i=i+2)
	{
		Rround_Times = (String[i+1]-'0');
		Current_Char = String[i];
		while (Rround_Times-- != 0)
			cout << Current_Char;
	}
}

void main()
{
	char *String = Create_String();
	The_Function(String);
	delete [] String;
}

- Moshe March 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string.h>
using namespace std;

char *Create_String()
{
char *String, *Temp;
Temp = new char[256];
gets(Temp);
String = new char[strlen(Temp)+1];
strcpy(String, Temp);
delete [] Temp;
return String;
}

void The_Function(char *String)
{
int Rround_Times;
char Current_Char;

for (int i=0 ; String[i] != '\0' ; i=i+2)
{
Rround_Times = (String[i+1]-'0');
Current_Char = String[i];
while (Rround_Times-- != 0)
cout << Current_Char;
}
}

void main()
{
char *String = Create_String();
The_Function(String);
delete [] String;
}

- Moshe March 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
int main()
{
string s,str;
cin>>s;
char tmp;
string digit="";
int j=0,t=0;
for(int i=1;i<s.length();i++)
{
digit=digit+s[i];
i++;
}

for(int i=0;i<s.length();i++)
{
j=digit[t]-48;
t++;
for(int k=0;k<j;k++)
str=str+s[i];

i=i+1;
}
cout<<str<<endl;
return 0;
}

- pinki kumari March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
int main()
{
string s,str;
cin>>s;
char tmp;
string digit="";
int j=0,t=0;
for(int i=1;i<s.length();i++)
{
digit=digit+s[i];
i++;
}

for(int i=0;i<s.length();i++)
{
j=digit[t]-48;
t++;
for(int k=0;k<j;k++)
str=str+s[i];

i=i+1;
}
cout<<str<<endl;
return 0;
}

- pkb March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// ZoomBA
/* 
We are assuming only alpha.
Thus, the general regex for the string is :
word -> [a-zA-Z][\d]+ 
s = ( word )+
Thus, the problem can be solved by tokenization of word
and then expanding the word
*/
word = '[a-zA-Z][\\d+]'
string = "a4b2c2a3f1g2"
println(string)
// tokenize on string 
l = tokens( string , word ) -> { 
  // extract letter 
  letter = (tokens($.o, '[a-zA-Z]' ))[0]
  // extract frequency
  frequency = (tokens($.o, '\\d+' ))[0]
  // expand the letter with frequency : a ** 2 -> aa 
  letter ** int(frequency) 
} 
// finally catenate over the list 
println( str(l,'') )

- NoOne March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var finalStr = '';str.forEach(function(v, i ) { if(i%2 == 0) { finalStr += v.repeat(str[i+1]); } });

- Alok Deshwal March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var finalStr = '';str.forEach(function(v, i ) { if(i%2 == 0) { finalStr += v.repeat(str[i+1]); } });

- Alok Deshwal March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var finalStr = '';str.forEach(function(v, i ) { if(i%2 == 0) { finalStr += v.repeat(str[i+1]); } });

- Alok Deshwal March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var finalStr = '';str.forEach(function(v, i ) { if(i%2 == 0) { finalStr += v.repeat(str[i+1]); } });

- Alok Deshwal March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var finalStr = '';str.forEach(function(v, i ) { if(i%2 == 0) { finalStr += v.repeat(str[i+1]); } });

- Alok Deshwal March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CharOccurAsNumber {

public String ModifyStringAsGivenNumber(String s)
{
String numbers="";
String chars="";
String result="";
if(s!="" && s!=null)
{
//extracting all the numbers from the given String in String format.
numbers=s.replaceAll("[^0-9]","");
//extracting all the characters from the given String in String format.
chars=s.replaceAll("[0-9]","");
//if the length of numbers and chars are same then proceed.
if(numbers.length()==chars.length())
{
for(int i=0;i<numbers.length();i++)
{
//Extracting the numbers one by one from the numbers String in String format.
String s1=numbers.substring(i,i+1);
//Extracting the characters one by one from the numbers String in String format.
String s2=chars.substring(i,i+1);
//parse the numbers from the SubString to Integer one by one.
int n=Integer.parseInt(s1);
//for the amount = the extracted number repeat the extracted Character and put it inside a String.
for(int j=0;j<n;j++)
result+=s2;
}
}
else
{
result="Inserted String format is wrong";
}
return result;
}
else
{
return "Empty String or no String inserted";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CharOccurAsNumber ob=new CharOccurAsNumber();
String s="a2b1c5e1g4";
String test=ob.ModifyStringAsGivenNumber(s);
System.out.println(test);

}
}

- Anonymous March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CharOccurAsNumber {

public String ModifyStringAsGivenNumber(String s)
{
String numbers="";
String chars="";
String result="";
if(s!="" && s!=null)
{
//extracting all the numbers from the given String in String format.
numbers=s.replaceAll("[^0-9]","");
//extracting all the characters from the given String in String format.
chars=s.replaceAll("[0-9]","");
//if the length of numbers and chars are same then proceed.
if(numbers.length()==chars.length())
{
for(int i=0;i<numbers.length();i++)
{
//Extracting the numbers one by one from the numbers String in String format.
String s1=numbers.substring(i,i+1);
//Extracting the characters one by one from the numbers String in String format.
String s2=chars.substring(i,i+1);
//parse the numbers from the SubString to Integer one by one.
int n=Integer.parseInt(s1);
//for the amount = the extracted number repeat the extracted Character and put it inside a String.
for(int j=0;j<n;j++)
result+=s2;
}
}
else
{
result="Inserted String format is wrong";
}
return result;
}
else
{
return "Empty String or no String inserted";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CharOccurAsNumber ob=new CharOccurAsNumber();
String s="a2b1c5e1g4";
String test=ob.ModifyStringAsGivenNumber(s);
System.out.println(test);

}
}

- Anonymous March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

java code

public static void main(String[] args) {
		String str = "a4b2c2a3f1g2";
		char cha[] = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		for(int i=0 ; i <  cha.length; i++) {
			concat(sb, cha[i], Character.getNumericValue(cha[i+1]));
			i++;
		}
		System.out.println(sb);
	}

	private static void concat(StringBuilder sb, char c, int d) {
		for(int i=0; i<d;i++) 
			sb.append(c);
	}

- Sudarsana Kasireddy March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		String str = "a4b2c2a3f1g2";
		char cha[] = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		for(int i=0 ; i <  cha.length; i++) {
			concat(sb, cha[i], Character.getNumericValue(cha[i+1]));
			i++;
		}
		System.out.println(sb);
	}

	private static void concat(StringBuilder sb, char c, int d) {
		for(int i=0; i<d;i++) 
			sb.append(c);
	}

- Sudar March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		String str = "a4b2c2a3f1g2";
		char cha[] = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < cha.length; i++) {
			concat(sb, cha[i], Character.getNumericValue(cha[i + 1]));
			i++;
		}
		System.out.println(sb);
	}

	private static void concat(StringBuilder sb, char c, int d) {
		for (int i = 0; i < d; i++)
			sb.append(c);
	}//

- Sudar March 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#Python code a2b8k9c14n2
import re
def printChar(alphabet, number):
    for i in range(0,number):
        print(alphabet, end='')


inputStr = input('Enter the String: ')
pattern ="[a-zA-Z]"
for i in range(0,len(inputStr)):
    if re.match(pattern,inputStr[i]):
        printChar(inputStr[i],int(inputStr[i+1]))

- Sugandha March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#Python code a2b8k9c14n2
import re
def printChar(alphabet, number):
    for i in range(0,number):
        print(alphabet, end='')


inputStr = input('Enter the String: ')
pattern ="[a-zA-Z]"
for i in range(0,len(inputStr)):
    if re.match(pattern,inputStr[i]):
        printChar(inputStr[i],int(inputStr[i+1]))

- Sugandha March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#Python code a2b8k9c14n2
import re
def printChar(alphabet, number):
    for i in range(0,number):
        print(alphabet, end='')


inputStr = input('Enter the String: ')
pattern ="[a-zA-Z]"
for i in range(0,len(inputStr)):
    if re.match(pattern,inputStr[i]):
        printChar(inputStr[i],int(inputStr[i+1]))

- Anonymous March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#Python code a2b8k9c14n2
import re
def printChar(alphabet, number):
    for i in range(0,number):
        print(alphabet, end='')


inputStr = input('Enter the String: ')
pattern ="[a-zA-Z]"
for i in range(0,len(inputStr)):
    if re.match(pattern,inputStr[i]):
        printChar(inputStr[i],int(inputStr[i+1]))

- Sugandha March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CharacterOccurence {

private static void characterPrint(String str) {
int count = 0;
while(count <= str.length()-2) {
char val = str.charAt(count);
String valCount = " "+str.charAt(count+1);
int len = Integer.parseInt(valCount);
int pointer = 0;
while(pointer <len) {
System.out.print(val);
pointer++;
}
count = count+2;
}

}
}

- nithin.mahadev March 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a basic approach would be to traverse the string from the beginning and add new character as needed.
Here is how it goes

public string transformString(string input)
{
	if(String.IsNullOrWhiteSpace(input))
	{
		return input;
	}
	StringBuilder s = new StringBuilder();
	int num = 0;
	int j = 0;
	while(j < input.Length && (input[j] >= 48 && input[j] <= 57))
	{
		s.Append(input[j]);
		j++;
	}
	for(int i = j; i < input.Length;i++)
	{
		num = 0;
		j = i+1;
		while((j < input.Length) && (input[j] >= 48 && input[j] <= 57))
		{
			num = num*10 + (input[j] - 48);
			j++;
		}
		while(num-- > 0)
		{
			s.Append(input[i]);
		}
		i = j;
	}
	return s.ToString();
}

Complexity is O(N) in Time and O(N) in space where N is the new size of the string(which is the size of the output string).

- sonesh March 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Exam{

public static void main(String[]args)
{
String gvn="a4b2c2a3f1g2";
String now="";
for(int k=1;k<gvn.length();k+=2)
{
for(int i=0;i<Character.getNumericValue(gvn.charAt(k));i++)
{
now+=gvn.charAt(k-1);
}
}
System.out.print(now);
}

}

- Anonymous April 26, 2017 | 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