Open In App

Contest Experience | Mega Job-A-Thon: Hiring Challenge for Freshers(5 July) Experience

Last Updated : 29 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This contest was a part of Job-a-Thon, a hiring challenge organized by GeeksforGeeks every month. It consisted of 3 coding problems.

Problem 1: Magic and toy shop

Approach:

  • The initial idea was to find the sum of the prices of all the toys and compare it with M. However the main issue was to minimize the operations when the sum was greater than M.
  • After many hits and trials, I realized that operations will be minimal for toys whose difference between magical_price and price is the highest.
  • It took me around 10-15 minutes to think of the idea and implement it.

Problem 2: Count beautiful strings

This was a little tricky problem. It took me multiple attempts and submissions to solve this one.

Attempt 1(TLE):

  • The initial method I thought of combines each pair and checks if it has at most one character whose frequency is odd.
  • However, this method failed for significant test cases since the constraint for String was 105, and resulted in TLE.

Attempt 2(TLE):

  • After some time I got another idea. The idea was to represent each string as a binary array of size 26 (the 0th index will represent ‘a’, the 1st index will represent ‘b’, and so on). Now the value of the ith index of this array will be 1 if the frequency of the character representing that index is odd or 0 otherwise. I used a map to store the frequency of this binary array.
  • However, this approach was still not efficient enough and I got TLE.

Attempt 3 (ACCEPTED):

  • It took me a little more time to optimize the above approach. I replaced the binary array with a number with a similar analogy (0th bit will represent ‘a’, 1st bit will represent ‘b’ and so on) and the ith index of this number will be 1 if the frequency of the character representing that index is odd or 0 otherwise.
  • It took me around 40 minutes to solve this problem.

Problem 3: Maximum good length

This problem seemed a lot easier to me than the 2nd problem as it was a standard binary search on answer problem.

Approach:

  • For any length L to be good we need to find L*L square matrix such that all elements is greater than or equal to L. I used the 2d prefix sum to determine if any length l is good or not. If length L is good, then I looked for numbers greater than l to be good; otherwise, if l was not good, then I looked for numbers smaller than length L.
  • It took me around 20 minutes to solve this problem.

Overall Summary:

Problem Name

Topic

Time Taken

No. Of Submissions

Magic and Toy shop

Greedy, Sorting

10 mins

1

Count beautiful strings

Hashing

40 mins

4 (3 Wrong Submission)

Maximum good length

Binary Search

20 mins

1


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads