Question: Byte Dance Intern OA
1
Entering edit mode

Medium

There were a total of 5 questions 2 mcq (one based on bit operations, and the next on stack operations) 3 coding (two medium and one hard question)

Click here to Practice

https://ibb.co/L1PW2Bq : The of the questions (medium)

 

Array operations are boring and fun! You are given two arrays of integers a1, a2,
an a and b1, b2, . . . , bn. Let's define a transformation of the array a: Choose any non-negative integer k such that 0 ≤ k ≤ n. Choose kdistinct array indices
1≤i1< i2 . . . < ig ≤ n Add 1 to each of Qi1, Qi2, • . • , Qik, all other elements
of array a remain unchanged. Permute the elements of array a in any order. Is it possible to perform some
transformation of the array a exactly once, so that the resulting array is equal to b?


Function Description


Complete the function trans formArray in the editor below. transformArray should return True if
array a can be transformed into array b
by the operation mentioned above, otherwise, return False.
transformArray has the following parameter(s):
a: a string representing array, each element is separated by space
b: a string representing array, each element is separated by space


Constraints

 

  •  n(1 ≤ n ≤ 106)
  • a1, a2,.. , a,(-106≤ ai ≤ 106)
  • b1, b2, - ..,bn (-106 ≤  bi ≤ 106)
Entering edit mode
0

Thanks! Could you also describe other questions?

ADD REPLYlink 2.2 years ago
sampriti
50
1
Entering edit mode

Question

Overview

  • Given two arrays A1 and A2 and both arrays have N integers
  • We have to choose K indexes from A2 and increase every element of those K indexes by 1.
  • Permute the A2 or A1 and tell if it is possible to make both arrays equally
  • If it is possible to make both arrays equal print 1 else print 0

Solution

  • We are given two arrays and we can choose any k integers from 0 to n-1.
  • Only operation we can do is in array A
  • Choosing K elements is nothing as we can choose from any k indexes from 0 to n-1 and increase one
  • The first thing we can do is sort both arrays in ascending order as mentioned we can permute this array, So it's not necessary for elements should remain in the same position
  • once we sort both of these arrays simply we can check if the array b[i] is greater than a[i] and the difference shouldn't be greater than one than we are good to go else if at any position if a[i] is greater than we can break our loop
  • If in any case, the absolute difference is greater than 1 we can break the loop and return 0 or NO as an answer
ADD COMMENTlink 2.2 years ago Akshay Sharma 990
Entering edit mode
1

[deleted]

ADD REPLYlink 2.2 years ago
Akshay Sharma
990

Login before adding your answer.

Similar Posts
Loading Similar Posts