Java Day 87: Binary Search Solution for LeetCode Challenge

⚡ 𝗗𝗮𝘆 𝟴𝟳 𝗼𝗳 𝗠𝘆 𝟭𝟬𝟬 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗗𝗦𝗔 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲! 𝘛𝘰𝘥𝘢𝘺’𝘴 𝘱𝘳𝘰𝘣𝘭𝘦𝘮 𝘸𝘢𝘴 𝘢 𝘨𝘳𝘦𝘢𝘵 𝘳𝘦𝘮𝘪𝘯𝘥𝘦𝘳 𝘵𝘩𝘢𝘵 𝘤𝘰𝘯𝘴𝘵𝘳𝘢𝘪𝘯𝘵𝘴 𝘰𝘧𝘵𝘦𝘯 𝘥𝘦𝘧𝘪𝘯𝘦 𝘵𝘩𝘦 𝘳𝘦𝘢𝘭 𝘤𝘩𝘢𝘭𝘭𝘦𝘯𝘨𝘦. 𝙏𝙝𝙞𝙣𝙠𝙞𝙣𝙜 𝙗𝙚𝙮𝙤𝙣𝙙 𝙗𝙪𝙞𝙡𝙩-𝙞𝙣𝙨! 📌 Problem Solved: 1️⃣ 𝗟𝗲𝗲𝘁𝗰𝗼𝗱𝗲 𝟯𝟲𝟳: 𝗩𝗮𝗹𝗶𝗱 𝗣𝗲𝗿𝗳𝗲𝗰𝘁 𝗦𝗾𝘂𝗮𝗿𝗲 (𝗘𝗮𝘀𝘆) ➡️ Without using built-in functions like sqrt(). ✨ Key Learnings: 🔹 Since using 𝘀𝗾𝗿𝘁() 𝘄𝗮𝘀 𝗻𝗼𝘁 𝗮𝗹𝗹𝗼𝘄𝗲𝗱, the solution required logical thinking instead of shortcuts. 🔹 A clean approach is using 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 between 1 and num, checking whether mid * mid == num. 🔹 This reduces 𝘁𝗶𝗺𝗲 𝗰𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 to: ✅ 𝗢(𝗹𝗼𝗴 𝗻) 𝗶𝗻𝘀𝘁𝗲𝗮𝗱 𝗼𝗳 𝗢(𝗻) 🔹 Important to 𝗵𝗮𝗻𝗱𝗹𝗲 𝗶𝗻𝘁𝗲𝗴𝗲𝗿 𝗼𝘃𝗲𝗿𝗳𝗹𝗼𝘄 while calculating mid * mid (use long if needed). 🧠 Big Takeaway: When shortcuts are removed, 𝗮𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺𝗶𝗰 𝘁𝗵𝗶𝗻𝗸𝗶𝗻𝗴 takes over. 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 isn’t just for arrays — it applies anywhere there’s a 𝘀𝗲𝗮𝗿𝗰𝗵 𝘀𝗽𝗮𝗰𝗲. Day 87 completed — 𝘁𝗵𝗶𝗻𝗸𝗶𝗻𝗴 𝗯𝗲𝘆𝗼𝗻𝗱 𝗯𝘂𝗶𝗹𝘁-𝗶𝗻𝘀! 💪🔥 #100DaysOfCode #DSA #Java #LeetCode #BinarySearch #ProblemSolving #InterviewPreparation #LearningInPublic #Developers #MathLogic #ProblemSolving #NumberTheory #InterviewPreparation #LearningInPublic #Developers

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories