Minimum Cost to Make an Array Monotonic
Updated
Problem statement
Replace array values by integers at cost |newValue - originalValue|. Return the minimum total cost needed to make the array non-decreasing or non-increasing.
Function
minMonotonicCost(arr: int[]) → longExamples
Example 1
arr = [1,5,2,4]return = 3Changing 5 to 2 yields the non-decreasing array [1,2,2,4] at cost 3.
Constraints
1 <= arr.length <= 2000-10^6 <= arr[i] <= 10^6- The answer fits in a signed 64-bit integer.
More Atlassian Online Assessment questions
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
- Largest Consistent Visiting GroupAuxoAI · OA
- Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
- Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
- Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
- Get Minimum IncrementIBM · OAIBM interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions