Komli Media Interview Question for SDETs


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
3
of 5 vote

it is like binary representation of 3 bits

001
010
011
100
101
110
111
where ever 1 is there insert that character

- Anonymous July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It won't work when there are duplicate characters Consider aaa. You will end up printing duplicates.

- alex July 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

// No input validation
public class SringPermuatation {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		strPrnt("abcd", null, 0);
	}

	private static void strPrnt(String S, String Fix, int fixedPost) {
		if (Fix == null) {
			System.out.println(S);
			Fix = "";
		} else {	
			if(S.equals(Fix))
				return;
			System.out.println(Fix);
		}

		for (int i = fixedPost; i < S.length(); i++) {

			strPrnt(S, Fix + S.charAt(i), i + 1);

		}

	}

}

- Venkat July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

doesnt Work...

- Anirudh July 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

System.out.println(S); is not needed. it will print the whole string one extra time

- Anonymous July 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

In C++:

#include <iostream>
#include <sstream>

using namespace std;

void combinationsString(string word, string out, int start)
{
	for(int i = start; i < word.length(); i++)
	{
		out += word.at(i);
		cout << out << endl;
		combinationsString(word, out, i + 1); 
		out.erase(out.length() - 1, 1);
	}
}

int main(int argc, const char * argv[])
{
	combinationsString("abc", "", 0);
        //Output: a, ab, abc, ac, b, bc, c
}

- NL July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you keep the number of arguments passed to the method to to under 3?

- Anirudh July 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.*;

class samp
{

public static void main(String args[])
{

String s="abc";
String s1;
StringBuilder sb= new StringBuilder();
int i,j=0;
int a=s.length();

for(i=0;i<=a;i++)
{

while(j<=a)
{
s1=s.substring(i,j);
sb.append(s1);
j++;
}

j=i+1;
}
System.out.println(sb);
}

}

- varadhan1127 July 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static void arrangeLettersToWordNoRepeat(char[] letters) {
		int n = (int) Math.pow(2, letters.length);
		for (int number = n - 1; number >= 0; number--) {
			if (number == 0) {
				System.out.print("empty string");
				break;
			}
			for (int position = letters.length - 1; position >= 0; position--) {
				if ((number & (1 << position)) != 0) {
					System.out.print(letters[letters.length - 1 - position]);
				}
			}
			System.out.println();
		}
	}

- Oleg G July 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

For some more sol:

question?id=4974004955774976

- PKT July 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The order doesn't matter.

- Anirudh July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Check my code i write Combinations function two ways use anyone
//My code is tested and compiled
#include<iostream>

using namespace std;



void PrintCombinations_other(char arr[],int i, int n, char result[], int j, int r)
{
   if(r == 0)
   {
      result[j] = '\0';
      cout<<result<<endl;
      return;
   }

   if(i + r -1 >=  n)
   {
      return;
   }

   for(int x = i; x + r - 1 < n; x++)
   {
      result[j] = arr[x];
      PrintCombinations_other(arr,x+1,n,result,j+1,r-1);

      while(arr[x] == arr[x+1])x++;
   }

}

void PrintCombinations(char arr[],int i, int n, char result[], int j, int r)
{
  

   if(j == r)
   {
      result[r] = '\0';
      cout<<result<<endl;
      return;
   }

   if(i == n)
   {
      return;
   }

   //include ith char or not include it 

   result[j] = arr[i];
   PrintCombinations(arr,i+1,n,result,j+1,r);

   //handle duplicates
   while(arr[i] == arr[i+1])
   i++;

   //do not include ith char
   PrintCombinations(arr,i+1,n,result,j,r);
}

void PrintAllLenStrings(char arr[])
{

  int len = strlen(arr);

  char* result = new char[len+1];

  for(int i = len; i >= 1; --i)
  {
     PrintCombinations_other(arr,0,len,result,0,i);
  }
}

int main()
{
   char arr[] = "abcd";
   PrintAllLenStrings(arr);
   return 0;
}

- Kavita July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i cant understand the o/p..anyboby explain

- vignesh July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What will be total number of combinations of choosing 1 or more things out of n distinct things?

- Anirudh July 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is an implementation which uses only one recursion parameter. Also this does not include checking for duplicates before printing. That needs to be accounted for.

#include<stdio.h>
#include<string.h>

char in[100], s[100];
int N;

void combRec(int i);
void remSpacePrint();

void main()
{
    scanf("%s",in);
    N=strlen(in);
    char s[100]={'\0'};
    combRec(0);    
}

void combRec(int i)
{
    if(i==N)
    {
        remSpacePrint();
        return;
    }
    s[i] = ' ';
    s[i+1] = '\0';
    combRec(i+1);
    s[i]=in[i];
    combRec(i+1);
}

void remSpacePrint()
{
    char new[100];
    int i=0,j=0;
    while(i<=N)
    {
        if(s[i]==' ')
        {
            i++;
            continue;
        }
        new[j++]=s[i++];
    }
    printf("%s\n", new);
}

- kr.neerav July 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream.h>
#include <math.h>
#include<conio.h>
void combination(char * array, int size)
{
  int n = pow(2, size);

  for (int i = n; i >= 1; --i)
  {
    int k = i,j=0,p =size-1;
    while (p >= 0)
    {
      k=k>>p;
      if (k & 1)
      {
	cout<<array[j];
      }
      j++;
      --p;
      k=i;
    }
    cout<<endl;
     }
}
void main()
{
char a[3] = {"abc"};
clrscr();
  combination(a,3);
getch();
}

- Ashraf July 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream.h>
#include <math.h>
#include<conio.h>
void combination(char * array, int size)
{
  int n = pow(2, size);

  for (int i = n; i >= 1; --i)
  {
    int k = i,j=0,p =size-1;
    while (p >= 0)
    {
      k=k>>p;
      if (k & 1)
      {
	cout<<array[j];
      }
      j++;
      --p;
      k=i;
    }
    cout<<endl;
     }
}
void main()
{
char a[3] = {"abc"};
clrscr();
  combination(a,3);
getch();
}

- Ashraf July 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Anirudh, can you share the algorithm/program in C to generate this; which avoids duplicates.
E.g. baca should print "aa", "ba" etc only once.

- Amit July 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can start with an empty array, then for each new character, just add that character to all existing members of the empty array we had. we save quite a bit of space complexity here and duplications.
on algorithm complexity, It is o(n*m)

here is my objective c version, shame there is no better way to work with characters and strings...

NSString *string = @"abc";
        
        NSMutableArray *characters = [NSMutableArray arrayWithCapacity:string.length];
        [string enumerateSubstringsInRange:NSMakeRange(0, string.length)
                                   options:(NSStringEnumerationByComposedCharacterSequences)
                                usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                    [characters addObject:substring];
                                    
                                }];
        
        NSMutableArray *output = [NSMutableArray arrayWithObject:@""];
        [characters enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
            NSArray *temporalOutput = [output copy];
            [temporalOutput enumerateObjectsUsingBlock:^(NSString *newInput, NSUInteger idx, BOOL *stop) {
                [output addObject:[newInput stringByAppendingString:obj]];
            }];
        }];
        
        NSLog(@"output %@", output);

- crisredfi1 July 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String s1="abc";
int n=s1.length();
for(int i=0;i<n;i++)
{
System.out.println(s1.charAt(i));
for(int j=i+1;j<n;j++)
{
System.out.print(s1.charAt(i));
System.out.print(s1.charAt(j));
System.out.println("");
}
}
System.out.println(s1);

- vikash July 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class RecursionAnagrams1 {
    private static void permutation(String prefix, String str){
        int n = str.length();
            System.out.println(prefix);
            for (int i = 0; i < n; i++)
                permutation(prefix + str.charAt(i), 
            str.substring(0, i) + str.substring(i+1));
    }
    public static void main(String[] args) {
        permutation("", "ABC");
    }

}

- Anonymous August 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

IN C#
string a="abc";
Console.WriteLine(a);
foreach (char i in a)
{
Console.WriteLine(i);
Console.WriteLine(a.Replace(i.ToString(), "").ToString());
}
Console.Read();

- Misa October 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// ZoomBA
def all_comb_words( string ){
  len = #|string| 
  words = fold ( [ 0: 2 ** len ] , set() ) -> {
    s = str( $.o,2) 
    s = ('0' ** ( len - #|s| ) + s )
    opt = fold ( s.value , '' ) -> { 
      $.p += ( $.o == _'1' ? string[ $.i ] : '' ) }
    opt  = str(opt) ; sorta(opt.value)  
    $.p += opt
  }
  println( words )
}
all_comb_words ( 'aabcc' )

- NoOne November 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Hey guys here order is matter because  through this order only we will finalize our algotm

here the code are:

package com.sunil.carrercup;

public class String_Order {

	/*
	Given a String with print all the possible combinations of the all the characters in the string as a string for Example

	"abc" is the input the you should print the below:
	
	abc
	
	ab
	
	ac
	
	a
	
	bc
	
	b
	
	c 
 */
	public static void main(String[] args) {
		
		String st="abcd";
		char take;
		
		System.out.println(st);
		for(int i=0;i<st.length();i++){
			take=st.charAt(i);
			//System.out.println(take);
			for(int j=i+1;j<st.length();j++){
				System.out.println(take+""+st.charAt(j));
			}
			System.out.println(take);
		}
	}
}

- sunil s July 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Doesn't give all possible substrings in case of "abcde".

- Anirudh July 05, 2014 | 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