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

Автор ChitreshApte, история, 5 лет назад, По-английски

Hi everyone, Infosys conducted the Hackwithinfy contest which just concluded yesterday. I found some questions very interesting but was not able to figure out solutions for those. Please share possible approaches or solutions for these. Any help will be appreciated.

Question 1

You are given 2 numbers N and M and an array of sizes N. A triplet is defined if it satisfies ANY ONE of the following conditions:

  1. All numbers in the triplet are the same (Eg. {1, 1, 1})

  2. The numbers are consecutive (Eg. {1, 2, 3})

Given the array, find the maximum number of triplets that can be formed. All elements in the array are <= M.

NOTE: Each element of the array can only be part of 1 triplet.

Constraints:
1 <= N <= 10^5
1 <= M <= 10^4
1 <= arr[i] <= M
Sample Input : 
4 2
1 2 2 2
Output : 1
Explanation: Only one triplet can be formed {2,2,2}

Question 2

You are given an array A of N elements. You need to divide the array into 4 non-empty contiguous subsequences B, C, D, E by making 3 cuts to it. Let P, Q, R, S be the sum of elements in the new arrays B, C, D, E.

Your task is to find the minimum possible absolute difference of the (maximum and minimum among P, Q, R, S)

Constraints:
4 <= N <= 10^5
1 <= A[i] <= 10^4
Sample Input : 
10
10 71 84 33 6 47 23 25 52 64
Output: 36

Question 3

(I am presenting the simplified form) We are given K arrays which are all permutations of numbers from 1 to N. The ith array represents the order of N people coming to a theatre on some ith day (1 <= i <= K). You have to find the maximum size of the group of people that come to the theatre in the same sequence each of the K days.

Constraints:
1 <= N <= 1000
1 <= K <= 10
1 <= a[i][j] <= N
Sample Input:
4 (this is N)
3 (this is K)
1 3 2 4 (day 1)
1 3 2 4
1 4 3 2 (day k)

Sample Output:
3
Explanation:
We can see people 1, 3, 2, they come in the same sequence all the days. So the answer is 3.

Note: This is a compilation of questions that were asked to different participants.

Thank You.

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

»
5 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится +17 Проголосовать: не нравится

Problem 1 is similar to this: Jongmah

Problem 3 is similar to this: Gargari and Permutations

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

2) I'm a bit skeptical about this, but it seems like a 3-pointers problem.

3) I believe that this is just the longest common subsequence of all $$$a_i$$$. That should run in $$$O(KN^2) \approx 10^7$$$.

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

Your slot was yesterday? My slot was on 7th May and problem 1 on my set was exactly same as yours. That's so unfair to those who had the earlier slots.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

Giving problems of rating 2200+ srsly? Infosys? .. ;(

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Can someone tell the algorithm for solving problem 3? I currently have $$$O(KN^K)$$$ solution.

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

Isn't problem 3 LCS?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

I wonder, what does Infosys want to prove by giving 2000+ rated problems in the contest. It isn't like they are going to give some 20 lpa. They would give a mere 5-7 LPA and they want red coders in their company lol.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

wtf is this??.. If someone can solve question of rating 2200 ,why will they go to infosys?

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

I had different questions. Did someone get the matrix question in which we had to throw out garbage?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I solved problem 2 but I am not sure if it is correct or not.

pre[i][0] = sum of subarray elements starting from o to l where(l < i)

pre[i][1]= sum of subarray elements starting from l + 1 to i

such that absolute difference between pre[i][0] and pre[i][1] is minimum.

also calculated suf[i][0], suf[i][1] for subarray from i to n — 1.

link to my code

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

2 is direct copy of this AtCoder problem (they even used the same variables lmao)

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
My Problems 10 May, 2021
»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

ANY HELP WILL BE APPRECIATED, THANKS IN ADVANCE :)

ANOTHER QUESTION FROM HACKWITHINFY 2020

Problem DIFFRENT ARRAYS
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

The question are worth more value than the company itself xD.

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

Can anyone help me with this problem asked in infytq link .

It would be great if author can add it to the post.

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

Can somebody explain me the DP approach of Qn1? I could not understand the editorial.1110D - Jongmah

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

Hii, for hackwithinfy i was using firefox and the timer wasn’t running but i was able to view and submit problems and after one hour i switched back to chrome will they disqualify me? Also will i get call for PP , I wad able to solve 2 problems full and 1 problem 78% .