Thoughtworks Placement question coderinme

 

Thoughtworks Placement question In AMU:

It was AMU Aligarh Placement drive for B.Tech/M.Tech/M.C.A. this was Thoughtworks first question for First round.
The Problem was to Make a dictionary and use a search option in c or c++ ,Java
for example if the words are cat ,rat ,sat ,mat ,toy ,at,brat
and user enter a word “rat” then output should be rat and at
or If user search “tab” then output should be all combination like bat tab at

We are providing Java solution for that question

package pr1;

import java.util.Scanner;
import java.util.StringTokenizer;

public class p1 {
	public static void main(String ...strings )
	{
		String []dic = {"bat", "trap", "rat", "at", "tab", "toy"};
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter a  ");
		String s = sc.nextLine();
		char []a = s.toCharArray();
		for(int i=0; i<dic.length; i++)
		{
			int n=0;
			for(int j=0; j<a.length; j++)
			{
				String ch = Character.toString(a[j]);
					if(dic[i].contains(ch))
					{
						n++;
						
					}
			}
			if(dic[i].length() == n)
				System.out.println(dic[i]);
		}
	}
}

Thoughtworks first question

Python 3.0 solution for that question

dict = ["bat","tab","rat","at","toy"]
str = str(input())
out = []
for i in range(len(dict)):
    for j in range(len(dict[i])):
        temp = dict[i]
        if temp[j] in str:
            x = 1
        else:
            x = 0
            break
    if x == 1:
            out.append(dict[i])
if len(out) > 0:
    for l in range(len(out)):
        print(out[l])
else:
    print('No possible word built')

2nd one

Solution provided by Shruti Singh/ Mohd Danish

ThoughtWorks more
Competitive questions
For other companies technical question.

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin@coderinme.com

We as Coder in Me appreciate the efforts to people who contribute their precious time for making this Community Contribution.We are open to guest Contribution, If you have interesting stuff to share please contact us

2 comments: On Thoughtworks Placement question coderinme

Leave a reply:

Your email address will not be published.