Блог пользователя MR_MECHANICAL

Автор MR_MECHANICAL, история, 4 года назад, По-английски

Hi All, I am new to Competitive Programming and today I attended an online interview in a company, I got two questions. but I did not solve even one of them completely. I was missing logic in both the question.

Q1. given an array of length N(always even length ) need to split this array into two N/2 subarrays (there are multiple orders we can split). for all the combinations of sub-array find the XOR value and print min and max value.

Eg: give array arr=[1,2,3,4] possible sub array splitting

(1,2) (3,4) finding xor for it (1^2) + (3^4) = 3+7 =10

(1,3) (2,4) finding xor for it (1^3) + (2^4) = 2+6 =8

(1,4) (2,3) finding xor for it (1^4) + (2^3) = 5+1 =6

Output: 6(min Val) , 10 (max Val)

Doubt: I don't even know how can I split it. if the array is of size 10 need to split subarray of size 5.

Q2. given two array, array1 has words and array2 has words with some char marked as "?", need to compare all the word in arry2 with array1 and output number of words in array2 matching array1. while comparing the position of the word in array1 and array2 also should need to be the same if "?" in a place means we can consider it as same char as arry1. Note: all the words are of the same length and of the smaller case only

Eg: array1 =["cat", "cap" , "map","man"] , array2=["c??","??p" ,"ma?"]

the word in array1 that matches are,

"c??" -> cat ,cap

"??p" -> cap, map

"ma?" -> map , man

Output: "c??" = 2 match

"??p" = 2 match

    "ma?" = 2 match

Note: Both the character and the position should need to be the same to get a match.

Doubt: I used trivial for a loop-based approach. it said Time limit exceed. don't know which algorithm to use to compare then quickly.

Please Help!!!!!

  • Проголосовать: нравится
  • -22
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How do we know contest ended or not?

»
4 года назад, # |
Rev. 3   Проголосовать: нравится -10 Проголосовать: не нравится

Second one is simple trie question.

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

you should mention the constraints as well, as the first one can be done with dp+bitmasks but for that constraints are important.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    N is even. N<=20 Array elements are 32bit integers.

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +11 Проголосовать: не нравится

      N<=20

      Oh god, people should start to realize that this is important information...

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Can you help me with this problem:- https://mirror.codeforces.com/blog/entry/76177 . This is the one I got in my 1 hour test, and I wasn't able to solve it (still haven't) even after trying different approaches. I am assuming that there exists a simpler solution than the one mentioned in the comments of the blog since the duration of test was of just 1 hour and also other problem's level was easy. I have tried dp approach with maps as well but got tle. Any help would be appreciated :).

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I don't understand why some people got such hard problems.

In my case it was a simple stack question for the first one. And second question was basic deque question.