Amazon ng Acreage | Amazon OA Fresh Interview Sharing | Two Questions in 13 Minutes

111 Views
No Comment

Just finished today's latest Amazon OA and came to the ground to return the favor. The questions were not too difficult, 70 minutes, but I finished them in 13-15 minutes and submitted them. As long as you are careful and don't write any bugs, you can basically get an AC, so I hope this helps those who are applying. Amazon NG Post students, cheers everyone!

Amazon OA Overall Difficulty & Thoughts

  • Platform: HackerRank
  • quantity of questions: 2 Programming Questions
  • Total duration: 70 minutes
  • My time spent: 13 minutes (T1 8 minutes + T2 5 minutes)
  • Difficulty Judgment: Easy-Medium, much simpler than the old OA that everyone on Acreage has been passing around!
  • direction of an exam point: Interval merge, greedy, sliding window, modulo allocation

Amazon's style of NG OA now is more on the side of "can you write the right basic code and handle the boundaries", not the tricky high-frequency questions that get stuck in your mind.

T1 - Interval Connectivity Reduction

You are given a set of intervals on the number line, allowing you to add a new interval of length no longer than k. The goal is to minimize the number of connected blocks in all intervals after addition, and return this minimum number. Two intervals are connected if they overlap or their endpoints touch.

The core of the problem-solving idea is actually the two steps of "merging intervals + sliding windows". First, all the given intervals must be sorted by the left endpoint, and then traversed once, merging the overlapping or encountered intervals into disconnected "connected blocks". For example, there were multiple overlapping intervals, but after merging, they become one large connected block, so that in the future, you only need to pay attention to the gaps between these connected blocks.

Next, we need to calculate the gap length between these connected blocks. For example, after merging, there are block 1 [start1, end1] and block 2 [start2, end2]. Then the gap between them is start2 minus end1. Our goal is to add a new interval of length no longer than k that covers as many of these gaps as possible - each gap covered reduces the number of connected blocks by one. At this time, we use the idea of ​​sliding windows to maintain a window and calculate the total length of continuous gaps in the window. As long as the total length does not exceed k, it means that these gaps can be filled by a new interval. Finally, use the initial number of connected blocks and subtract the maximum number of gaps that the window can cover to get the minimum possible number of connected blocks.

Common error-prone areas: first, forgetting to sort by the left endpoint before merging the range, resulting in a merge error; second, writing start [i+1] and end [i] backwards when calculating gaps; third, the left pointer of the sliding window is not advanced correctly, creating an infinite loop; fourth, when judging the coverage length, the "equal to k" situation is missed.

T2 — Maximizing Distinct Hash Values

Give you an array of integers param, you can choose an equal-length array of non-negative integers secretKey. Definition Hash[i] = secretKey[i] % param[i], let Hash maximum number of different values ​​in the array is returned.

This problem can be solved using a greedy algorithm. The key is to sort the param array first. The core idea is to try to generate consecutive small hash values ​​such as 0, 1, and 2, because the result of the modular operation is definitely smaller than the modulus itself.

The specific method is: first sort the param array from small to large, and then maintain a variable current_val and it is 0 at the beginning, representing the hash value we currently want to get. Then traverse the sorted param array: If current_val is smaller than the current param [i], then we can choose a suitable secretKey so that its modulo of param [i] is equal to current_val. At this time, add 1 to current_val and continue to the next one; if current_val is greater than or equal to param [i], it means that this param [i] is too small to generate such a large remainder and can only be skipped. The final value of current_val is the maximum number of different hash values ​​that can be obtained.

Common error-prone areas: First, the param array is not sorted, and the greedy logic cannot take effect; second, it is not considered that when param [i] is equal to 1, the modulo can only get 0, and other values ​​cannot be generated; third, the growth logic of current_val is written incorrectly; fourth, the "maximum number of different hash values" is misunderstood as the number of elements in the param array after deduplication.

Although this set of questions is not difficult, for those who haven't brushed up on Interval or Constructive Greedy, it's still a lot of pressure to finish it in 70 minutes and debug it successfully. If you're still not sure about OA, or if you're afraid to click on the HackerRank link soon, look below!

Final Quarter Lifesaver! Can't get your CS assignment/project done? Look for Programhelp

Want to bend the curve of the intense job search season?Programhelp Provide you with hardcore assists in the whole process from OA to Offer.

be directed against OA We use ToDesk to operate remotely without traces, support HackerRank, Codesignal and other platforms, and promise a 100% pass rate, secure and hidden, but no charge.

exist VOWe provide flexible solutions: North American CS experts provide real-time idea prompts (covering Code, BQ, System Design) through self-developed no-trace documents to help you answer questions fluently; we also have a substitute interview service based on camera and voice-altering technology, which supports the mode of "lip-synching" or "all-alternative". There are also camera and voice-change based interviewing services, supporting "lip-sync" or "full substitution" modes, which can perfectly solve the problem of stage fright.

We also have a full set of Offer Package, from OA, interview to salary negotiation, one-stop service until you get a satisfactory offer, leave the professional things to us, you just need to prepare for the job!

The job search in NG is really brutal and everyone is grabbing the same opportunities.
But the competition in this class is not about who knows the harder questions, but about who is more consistent, faster, and makes fewer mistakes.
So if you're stressed and anxious right now - don't worry, we've all been there.
Taking it one step at a time and holding OA steady is the best place to start.
Good luck with the "Congratulations!" email.

author avatar
jor jor
END
 0