In-place List Rearrangement Challenge

🚨 Interview Experience Today 👇 Problem: Input: [0,1,0,3,12] Output: [1,3,12,0,0] ⚠️ Constraint: Do not create new/another list ⸻ 💭 My attempt (under time pressure): print(f”[{nums[1]}, {nums[3]}, {nums[4]}, {nums[0]}, {nums[0]}]”) Output: [1, 3, 12, 0, 0] ❌ Rejected ⸻ 💡 Approach shared after: nums = [num for num in nums if num != 0] + [0] * nums.count(0) print(nums) 🤔 I pointed out that this still creates a new list ⸻ 🧠 My Question: 👉 Would this still be considered valid given the constraint? 👉 Or should the expectation strictly be an in-place solution? ⸻ 💬 Curious to hear how you would approach this! #InterviewExperience #Python #CodingInterview #DataStructures #Learning #BackendDevelopment #SoftwareEngineering

To view or add a comment, sign in

Explore content categories