0% found this document useful (0 votes)
23 views5 pages

Kaar Techs Problem Solving Questions

The document outlines three coding problems involving arrays and mathematical operations. The first problem requires finding the minimum possible XOR value from splitting an array into intervals, the second involves calculating a power of 2 based on squared elements and their binary representations, and the third focuses on deriving values of M and D from a given equation. Each problem includes examples to illustrate the expected outputs.

Uploaded by

apkfour5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Kaar Techs Problem Solving Questions

The document outlines three coding problems involving arrays and mathematical operations. The first problem requires finding the minimum possible XOR value from splitting an array into intervals, the second involves calculating a power of 2 based on squared elements and their binary representations, and the third focuses on deriving values of M and D from a given equation. Each problem includes examples to illustrate the expected outputs.

Uploaded by

apkfour5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Kaar technologies java coding question which was asked yesterday sir

input1: an integer, representing the size of an array a


input2: an integer array a
Output: return an integer value representing the minimum possible XOR value that can
be achieved

Example 1:
input1 = 3
input2 = {1, 5, 7}
Explanation: Split into two intervals: {1, 5} and {7}
OR({1, 5}) = 5
OR({7}) = 7
XOR(5, 7) = 2 → this is the minimum possible XOR we can get

Example 2:
input1 = 3
input2 = {7, 7, 7}
Possible split: {7}, {7, 7}
OR({7}) = 7, OR({7, 7}) = 7
XOR(7, 7) = 0 → this is the minimum

2. You are given an integer array arr. Perform the following operations:

Steps:
Square every element in the array.

Convert each squared number to binary format.

Count the number of 1's in the binary string.


Among all squared numbers:

Let a be the number with the maximum count of 1s.


If there are multiple such numbers, pick the smallest one.

Let b be the number with the minimum count of 1s.


If there are multiple such numbers, pick the smallest one.

Compute c = a × b.

Find the smallest power of 2 (i.e., 2^x) such that 2^x ≥ c.

Return that power of 2 value as the final answer.

Example 1:
Input:
arr = [2, 3, 4]

Steps:

Squares → [4, 9, 16]

Binary → 100 (1), 1001 (2), 10000 (1)

Max 1s = 2 → 9 → a = 9

Min 1s = 1 → choose smallest of 4, 16 → b = 4

c = 9 * 4 = 36
Nearest power of 2 ≥ 36 → 64

Output:
64

Example 2:
Input:
arr = [5, 6, 7]

Steps:

Squares → [25, 36, 49]

Binary → 11001 (3), 100100 (2), 110001 (3)

Max 1s = 3 → [25, 49] → take smaller → a = 25

Min 1s = 2 → b = 36

c = 25 * 36 = 900

Nearest power of 2 ≥ 900 → 1024

Output:
1024

Example 3:
Input:
arr = [1, 2, 3, 4]
Steps:

Squares → [1, 4, 9, 16]

Binary → 1 (1), 100 (1), 1001 (2), 10000 (1)

Max 1s = 2 → a = 9

Min 1s = 1 → [1, 4, 16] → pick 1 → b = 1

c=9*1=9

Nearest power of 2 ≥ 9 → 16

Output:
16

3. They will give two inputs N and A


The equation is N = A * M + D
You have to find M and divisor of M which is D
Then for all possible D values, add all the M values and return sum.

Sample input 1:
85
4

Possible values of M = 17,20,21


Output = 58 (17+20+21)
Sample Input 2:
35
3

Possible values of M = 10
Output = 10

You might also like