Swapnil Gore’s Post

🚨 Can you solve this without using Math.max()? Find the largest number in an array 👇 👉 [3, 7, 2, 9, 5] → 9 Most developers jump straight to Math.max(). But in interviews, that’s not enough. 💡 Method 1: Math.max(...arr) → quick & clean 💡 Method 2: Loop and track the max value 🔥 What interviewers actually test: Your logic, not shortcuts. ⚠️ Important: Always handle the empty array edge case 👉 Pro tip: Start with the first element (not 0 — breaks for negative numbers) Small details = big difference in interviews. Can you write both without help? 👇 Save this for interviews 🚀 #JavaScript #CodingInterview #Frontend #Developers #InterviewPrep

  • text

I'd push back on starting with the first element. Initialize to negative Infinity instead. It handles empty arrays and negatives cleanly, without the extra conditional interviewers always ask about.

Like
Reply

To view or add a comment, sign in

Explore content categories