Maximum Easy Tasks After Rearranging
Updated
Problem statement
You are given an integer array taskDifficulty. You may rearrange its elements in any order.
A task is easy when both conditions hold:
- It has an immediate neighbor on its left and on its right, so the first and last positions cannot be easy.
- Its difficulty is strictly less than the difficulties of both immediate neighbors.
Return the maximum possible number of easy tasks after rearranging the array.
Function
getMaximumTasks(taskDifficulty: int[]) → intExamples
Example 1
taskDifficulty = [4,5,6,1,2]return = 2One optimal order is [4,1,5,2,6]. The values 1 and 2 are each strictly smaller than both immediate neighbors, so two tasks are easy.
Constraints
1 <= taskDifficulty.length <= 2 * 10^5.1 <= taskDifficulty[i] <= 10^9.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
- Query Type Frequency WindowOA · Seen Oct 2026
Similar questions at other companies
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
- Minimum Days to Watch All MoviesAdobe · OAAdobe interview questions
- Efficient Janitor TripsRoblox · OARoblox interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
- Get Maximum PairsAmazon · OA