Given an array of integers and a new id, return the array with the new id if it already exists in the array, otherwise return the array with the new id appended.
Explanation: Step-by-step: Given the array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and the new id 7, we check if 7 exists in the array. Since it does, we return the array with 7. No additional id is appended.
Explanation: Step-by-step: Given the array [1, 2, 3, 4, 5, 6] and the new id 4, we check if 4 exists in the array. Since it does, we return the array with 4. No additional id is appended.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak