## Booking.com Interview Question for Software Engineers

Country: Netherland
Interview Type: Phone Interview

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

``````import java.util.ArrayList;

public class checksqrt {

public static void main(String[] args) {
// TODO Auto-generated method stub

int[] a= {3,1,4,5,19,6};
int[] b={14,9,22,36,8,0,64,25};
ArrayList<Integer> c=new ArrayList<Integer>();

for(int i=0;i<a.length;i++)
{
}

for(int j=0;j<b.length;j++)
{
if(c.contains(b[j]))
{
System.out.println(b[j]);
}
}
}

}``````

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

Effective Java solution using HashSet

``````import java.util.*;
import java.io.*;

public class Solution {

public static void main(String[] args) {
new Solution().solve();
}

public void solve() {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] a = {3, 1, 4, 5, 19, 6};
int[] b = {14, 9, 22, 36, 8, 0, 64, 25};

List<Integer> result = findSquares(a, b);

for (int cur : result)
out.println(cur);

out.close();
}

// search a[i]^2 in b
public List<Integer> findSquares(int[] a, int[] b) {
List<Integer> result = new ArrayList<>();
Set<Integer> squares = new HashSet<>();
for (int i = 0; i < a.length; i++)

for (int i = 0; i < b.length; i++)
if (squares.contains(b[i]))

return result;
}
}``````

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

sort the second array and do binary search or want to optimize more check the lenght of both the array andsort the larger one and do binary search on it...

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

1) Insert 2nd array values into hash map
2) Iterate through 1st array and square each value
3) Check for squared value in hash map and print match

If you replace unordered_map ( find() runs O(n) time as worst case) with your own hash map and assume no collisions, this solution runs in O(n) time complexity.

``````void CheckSquares(int *a1, int *a2, int len1, int len2){

std::unordered_map<int, bool> ht;
int temp;
int i;

// 1) Insert 2nd array values into hash map
for(i = 0; i < len2; i++)
ht[ a2[i] ] = 1;

// 2) Iterate through 1st array, square the values and print matches
for(i = 0; i < len1; i++) {
temp = pow(a1[i], 2);
if( ht.find( temp ) != ht.end() )
std::cout << temp << std::endl;
}

}``````

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

``````def findSquaresInArray(a1, a2):
n1 = len(a1)
n2 = len(a2)

if n2 == 0 or n1 == 0:
return None

hashmap = {}
results = []

for el in a1:
hashmap[el] = True

for el in a2:
root = pow(el, 0.5)
int_root = int(root)
if root != int_root:
continue

pos_root = hashmap.get(int_root)
neg_root = hashmap.get(-1*int_root)

if pos_root == True:
results.append(el)

elif neg_root == True:
results.append(el)

else:
continue

return results``````

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

<?php

\$a=[3,1,4,5,19,6];
\$b=[14,9,22,36,8,0,64,25];

for(\$i=0;\$i<count(\$a);\$i++)
{
for(\$j=0;\$j<count(\$b);\$j++)
{
if((\$a[\$i]*\$a[\$i])==\$b[\$j])
{
echo \$b[\$j]."<br>";
}
}
}

?>

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

``````import java.util.ArrayList;

public class checksqrt {

public static void main(String[] args) {
// TODO Auto-generated method stub

int[] a = { 3, 1, 4, 5, 19, 6 };
int[] b = { 14, 9, 22, 36, 8, 0, 64, 25 };
ArrayList<Integer> c = new ArrayList<Integer>();

for (int i = 0; i < a.length; i++) {
}

for (int j = 0; j < b.length; j++) {
if (c.contains(b[j])) {
System.out.println(b[j]);
}
}
}

}``````

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

``````def findSquare(a,b):
return list(set(map(lambda x:x**2,a)) & set(b))``````

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

def findSquare(a,b):
return list(set(map(lambda x:x**2,a)) & set(b))

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

def findSquare(a,b):
return list(set(map(lambda x:x**2,a)) & set(b))

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

``````var arr = []
for (i in a, b) {
var index = b.indexOf(Math.pow(a[i], 2))
if (index > -1) {
arr.push(b[index])
}
}
return arr``````

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

``````import java.util.*;

public class Solution {
public static void main (String args[]) {
int [] array1 = new int[] {3,1, 4, 5, 19, 6};
int [] array2 = new int[] {14, 9, 22, 36, 8, 0, 64, 25};
List<Integer> list = new Solution().solve(array1, array2);
for (int i : list)
System.out.println(i);
}
private Node root;
}
private void add(Node node, int value) {
if (root == null) {
root = new Node(value);
}else{
if (node.value > value) {
if (node.left == null) {
node.left= new Node(value);
}else{
}
}else{
if (node.right == null) {
node.right = new Node(value);
}else{
}
}
}
}
private Node find(int value) {
return find(root, value);
}
private Node find(Node node, int value) {
if (node == null)
return null;
if (node.value == value)
return node;
if (node.value > value)
return find(node.left , value);
return find(node.right, value);
}
public List<Integer> solve(int [] array1, int [] array2) {
for (int i : array1) {
}
for (int i : array2) {
int sqare = (int) Math.sqrt(i);
Node node = find(sqare);
if (node != null && (sqare * sqare == i)){
}
}
return list;
}
}
class Node {
int value;
Node left, right;
public Node(int value) {
this.value = value;
this.left = null;
this.right= null;
}
}``````

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

``````public void findSquares()
{
int[] a = {3, 1, 4, 5, 19, 6};
int[] c = {14, 9, 22, 36, 8, 0, 64, 25};
int isit = 0;
Set <Integer> b = new HashSet<Integer>();

for(int i=0;i<c.length;i++)
{
}

for(int j=0;j<a.length;j++)
{
isit = a[j] * a[j];
if(b.contains(isit))
System.out.print(isit + " ");
}
}``````

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

Below code in C#

``````public List<int> Result(int[] a,int[] b){
List<int> res = new List<int>();
HashSet<int> hs1 = new HashSet<int>(a);
HashSet<int> hs2 = new HashSet<int>(b);

foreach(var ele in hs2)
{
int sqrt = (int)Math.Sqrt(ele);
if (sqrt * sqrt == ele && hs1.Contains(sqrt))
}
return res
}``````

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

``````for i in a:
for j in b:
if i**2 == j:
print(j)``````

9
25
36

Its a linear solution, but it works

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

``````for i in a:
for j in b:
if i**2 == j:
print(j)``````

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

``````<?php

\$a=[3,1,4,5,19,6];
\$b=[14,9,22,36,8,0,64,25];

for(\$i=0;\$i<count(\$a);\$i++)
{
for(\$j=0;\$j<count(\$b);\$j++)
{
if((\$a[\$i]*\$a[\$i])==\$b[\$j])
{
echo  \$b[\$j]."<br>";
}
}
}

?>``````

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

``````<?php

\$a=[3,1,4,5,19,6];
\$b=[14,9,22,36,8,0,64,25];

for(\$i=0;\$i<count(\$a);\$i++)
{
for(\$j=0;\$j<count(\$b);\$j++)
{
if((\$a[\$i]*\$a[\$i])==\$b[\$j])
{
echo  \$b[\$j]."<br>";
}
}
}

?>``````

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.

### 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.