Interview Question

QA Analyst Interview

-Bangalore

Thoughtworks

6. Coding Questions Asked to screenshare in the hangouts, and asked to open the eclipse, gave two problems to solve. 1. Check when multiplying a 6 digit number with 2 gives a number which has all the same numbers. E.g: 142857 x 2 = 285714

Answer

Interview Answers

7 Answers

1

public class MirrorImageNumbers { public static void main(String[] args) { int number = 142857; int mul = 2; int ans = (number * mul); // int 285714 String s1 = String.valueOf(number); String s2 = String.valueOf(ans); System.out.println(s1 + " , " + s2); char ch1[] = s1.toCharArray(); char ch2[] = s2.toCharArray(); String sort1 = ""; String sort2 = ""; Arrays.sort(ch1); for (char i : ch1) { sort1 = sort1 + i; } Arrays.sort(ch2); for (char i : ch2) { sort2 = sort2 + i; } System.out.println(sort1 + " " + sort2); if(sort1.equals(sort2)) System.out.println("Mirrored!!"); else System.out.println("Wrong!!"); } }

Anonymous on

1

public static boolean checkNumber(int num) { int numTwice=num*2; String number = String.valueOf(num); char[] c = number.toCharArray(); List lic = new ArrayList(); for(char cc:c) { lic.add(cc); } String number2 = String.valueOf(numTwice); char[] c2 = number2.toCharArray(); List lic2 = new ArrayList(); for(char cc:c2) { lic2.add(cc); } Collections.sort(lic); Collections.sort(lic2); System.out.println(lic.toString()); System.out.println(lic2.toString()); if(lic2.equals(lic)) return true; else return false; }

Shubham on

1

Without Using Collections! int x=142857 ; int r=x * 2; // To take the count of numbers 0-9 int a[]=new int[10]; while(x>0){ int t=x % 10; a[t-0]++; x /=10; } while(r>0){ int t=r%10; a[t-0]--; r /=10; } boolean flag=false; for(int p:a){ if(p!=0){ flag=true; System.out.println("Not Equals"); break; } } if(!flag) System.out.println("Equals");

GnanaJeyam on

0

Answer: def CheckNum(num): exists = True if num > 999999 or num <= 100000: return "Enter six digit number" else: num2 = num * 2 lst = list(str(num)) lst2 = list(str(num2)) for i in range(len(lst)): if not lst.__contains__(lst2[i]): exists = False return exists

Kunal Tanti on

0

#include using namespace std; int digickeck(long int x) { int flag=0; do { flag=flag|(1>n; if(digicheck(n)==digicheck(n*2)) cout<<"Valid " ; else cout<<"Invalid"; return 0; }

HARI PREM KUMAR on

0

#include using namespace std; int digickeck(long int x) { int flag=0; do { flag=flag|(1>n; if(digicheck(n)==digicheck(n*2)) cout<<"Valid " ; else cout<<"Invalid"; return 0; }

HARI PREM KUMAR on

0

// Javascript function mirrorNumber(number=142857) { let mirrorNum = number * 2; number = number.toString(); mirrorNum = mirrorNum.toString(); function convertStringToArray(str) { let tmp = []; for(let i = 0; i arr[j]){ let tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } } return arr; } number = sort(convertStringToArray(number)); mirrorNum = sort(convertStringToArray(mirrorNum)); for(let i = 0; i < number.length; i++){ if(number[i] !== mirrorNum[i]) return false; } return true; } console.log(mirrorNumber()? "The number is mirrored" : "The number is not mirrored");

Naren Chejara on

Add Answers or Comments

To comment on this, Sign In or Sign Up.