Open In App

Contest Experience: GeeksforGeeks Mega Job-A-Thon: Hiring Challenge for Freshers

Last Updated : 04 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

About Job – A – Thon :
Job – A – Thon is a monthly Hiring Challenge by GFG, a single challenge used by multiple companies. 
Showcase your skills and land your dream job! 

This contest consists of 4 parts :
3 DSA coding problem – 100 marks
5 MCQ on Programming Logic – 25 marks
5 MCQ on Logical Reasoning – 25 marks
5 MCQ on Quantitative Aptitude – 25 marks

My Contest Experience:

In this post, I am going to share my experience of attempting the DSA coding problems of the Contest.

Problem Name

Difficulty

Pre-requisite

Approx time to solve

Number of submissions by me.

Magic and Toy Shop

Easy

Greedy + sorting

2 – 3 min

1

Count beautiful strings

Medium – hard

Hashing + Bit Manipulation

35 – 40 min

3(2 TLE)

Maximum good length

Medium

2DPrefix sum + Binary Search

20 min

1

Question 1: Magic and Toy Shop.

We have N toys of price[i] for the ith toy and there is a special magical_price[i] for the ith toy which is less than the price[i], we have to buy all toys in Atmost M rupees and we can buy toys on magical_price, so Geek wants to use the minimum number of magical prices to buy all toys.

Idea:

This problem is based on Greedy.

If we have to minimize the number of used magical_price, to do so we need to use the magical_price which causes maximum benefit. I sorted all the benefits in decreasing order and took them one by one and subtracted them from cost.

Once the cost becomes less than M then we return the index number which is our answer.

Question 2: Count beautiful strings:

Given N strings which contain only lowercase alphabets. We have to count the pairs such that by concatenating the strings should be Beautiful.
A string is beautiful if strings has at most one character whose frequency is odd and the rest of all (if exist) characters have even frequencies.

Idea:

Approach 1 gave me a TLE:

My first approach while reading this question is Brute force in which we have to just concatenate every pair of strings and check whether it is beautiful or not but this will give a TLE.

Approach 2 Gave me a TLE:

By reading the problem I understood that we can make string beautiful if all the characters have even frequencies or one of them has odd frequencies and the rest characters have even frequencies.

I started thinking like this for one string there are how many strings possible that can make beautiful by connecting them. To find such strings first I have taken a vector of size 26 used to store 0 if the frequency of the char is even and 1 if the frequency of the char is odd.

Then After generating that vector for the current string we search for a vector in the map that is the same as a generated vector which is the case for all even frequencies and then we generate a vector for one char having an odd frequency and the rest having even frequencies and then we search for the same and increment the count and once for the current string we count the all possible pairs then we insert the vector for the current string in map.

Approach 3 Gets accepted with slight modification to Approach 2:

So to overcome this I use a number to store the same thing that I have stored in a vector in bits of a number.
Like if the bit is 1 it means the char corresponding to that has an odd frequency and 0 if the frequency is even.

Question 3: Maximum good length:

You are given a matrix A of size N*M. Any length ‘L’ can be called good length if there is at least one square matrix of size L*L in A such that all elements in that square matrix are greater than or equal to L. You need to output the maximum good length for the given matrix.

Approach:

This is the question based on the 2D PrefixSum+ Binary Search on the answer and it looked familiar to me.

The reason why I thought of binary search is if I somehow found the square matrix of size LxL then it is guaranteed that any square less than LxL is present for sure then just need to find squares greater than LxL.
Then I thought of How I get to know whether for a square of LxL is present or not then to do so I used the 2D prefix sum.

For a mid, I mark cell 1 if it is greater than L and 0 if less than L and take the 2D prefix.
Then I traverse all the squares of size midXmid. If the sum of cells in squares is equal to midXmid then we have found and then searched for greater length else not then searched for lesser length.


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

Similar Reads