Deloitte · Question 25
Maximum Product of Two Elements
Problem
Find the max product (nums[i]-1)*(nums[j]-1).
Approach
Sort the array or find the top two max values.
Time O(n)Space O(1)
How it works
- 1Track the two largest values in one pass.
Sample input / output
Input: nums = [3, 4, 5, 2] Output: 12
Constraints
2 <= nums.length <= 500; 1 <= nums[i] <= 10^3.
Solution — read it, then walk it
Time O(n)Space O(1)Loops 1Branches 2Returns 1source · Java
Scroll sideways for wide charts — the view follows the active step.
- start / end
- statement
- condition
- loop
- returns
- definition
1/13
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits