Amazon SDE Intern OA – Round 1 Questions (Need Approach Help)
Summary
I completed the first question of the Amazon SDE Intern online assessment but got stuck on the second one.
Full Experience
Hi everyone,
I recently appeared for an Amazon SDE Intern Online Assessment and was able to solve the first question, but I got stuck on the second one.
Question 1: Feasible Indices After Prefix/Suffix Reduction
📄 Problem Statement
You are given an integer array arr of size n, where all elements are distinct.
You can perform the following operations any number of times:
- Choose a non-empty prefix of the array and delete all elements except the minimum element of that prefix.
- Choose a non-empty suffix of the array and delete all elements except the maximum element of that suffix.
After each operation, the remaining elements are concatenated to form a new array.
Task
An index i is called feasible if it is possible to reduce the array to a single element [arr[i]] using the above operations.
Return a binary string of length n where:
1→ feasible index0→ not feasible
Constraints
1 ≤ n ≤ 2 × 10^51 ≤ arr[i] ≤ 10^6- All elements are distinct
Example
Input:
arr = [1, 3, 2, 5, 4]
Output:
10011
🧠 Approach Idea (High-Level)
- Prefix operation → keeps minimum
- Suffix operation → keeps maximum
- So an element survives if:
- It behaves like a prefix minimum, OR
- It behaves like a suffix maximum
Efficient approach uses:
- Prefix minimum tracking
- Suffix maximum tracking
🤔 Need Approach Help
Question 2: Secure Maximum Deliveries
📄 Problem Statement
You are given:
- An array
deliveryLogsof sizen, where each value represents deliveries in a log - An even integer
krepresenting number of warehouses
📦 Storage Rules
- Each warehouse stores deliveries from only one log
- A log can be split across multiple warehouses
- Deliveries from different logs cannot be mixed
After storing:
- The largest k/2 warehouses are compromised ❌
- The remaining k/2 warehouses are safe ✅
Task
Return the maximum number of deliveries that can be stored safely.
Constraints
1 ≤ n ≤ 10002 ≤ k ≤ 1000kis even0 ≤ deliveryLogs[i] ≤ 1000
Example 1
Input:
deliveryLogs = [3, 5, 9, 6]
k = 4
Output:
9
Example 2
Input:
deliveryLogs = [6]
k = 2
Output:
3
It Feels Difficult
Looking For Guidance Could someone please guide me on: What is the correct intuition for this problem?
🚀 Interview Reflection
- Solving Q1 ✔️
- Struggling in Q2 ❗
**Good progress — Continue learnig... ** Thanks in advance!
Interview Questions (2)
Feasible Indices After Prefix/Suffix Reduction
You are given an integer array arr of size n, where all elements are distinct.
You can perform the following operations any number of times:
- Choose a non‑empty prefix of the array and delete all elements except the minimum element of that prefix.
- Choose a non‑empty suffix of the array and delete all elements except the maximum element of that suffix.
After each operation, the remaining elements are concatenated to form a new array.
An index i is called feasible if it is possible to reduce the array to a single element [arr[i]] using the above operations.
Return a binary string of length n where 1 indicates a feasible index and 0 otherwise.
Constraints:
- 1 ≤ n ≤ 2 × 10⁵
- 1 ≤ arr[i] ≤ 10⁶
- All elements are distinct
Example:
Input: arr = [1, 3, 2, 5, 4]
Output: 10011
Secure Maximum Deliveries
You are given an array deliveryLogs of size n, where each value represents deliveries in a log, and an even integer k representing the number of warehouses.
Storage Rules:
- Each warehouse stores deliveries from only one log.
- A log can be split across multiple warehouses.
- Deliveries from different logs cannot be mixed.
After storing, the largest k/2 warehouses are compromised and the remaining k/2 warehouses are safe.
Return the maximum number of deliveries that can be stored safely.
Constraints:
- 1 ≤ n ≤ 1000
- 2 ≤ k ≤ 1000, k is even
- 0 ≤ deliveryLogs[i] ≤ 1000
Example 1:
Input: deliveryLogs = [3, 5, 9, 6], k = 4
Output: 9
Example 2:
Input: deliveryLogs = [6], k = 2
Output: 3