🧩 DSA Problem: Alternate Elements of an Array Here’s a simple yet important problem to test your fundamentals 👇 👉 Question: Given an array, print every alternate element starting from the first index (0, 2, 4, ...) 🧪 Example Input: [10, 20, 30, 40, 50] Output: 10 30 50 💡 This problem helps you understand: ✔ Array traversal ✔ Index-based logic ✔ Space vs in-place optimization 🚀 I’ve explained multiple approaches (optimized + beginner-friendly) in detail here: https://lnkd.in/geXA-etA https://lnkd.in/gSPwE85b 💬 How would you solve this — in-place or using a new array? #JavaScript #DSA #CodingInterview #WebDevelopment #100DaysOfCode
Alternate Array Elements: DSA Problem with JavaScript Solutions
More Relevant Posts
-
🧠 DSA Practice Question – Remove Duplicates from Array 🔹 Problem Statement: Given an array (sorted or unsorted), remove all duplicate elements and return a new array containing only unique values. 🔹 Examples: Input: [1, 1, 8, 2, 3, 3, 4, 4] Output: [1, 8, 2, 3, 4] Input: [4, 3, 2, 1] Output: [4, 3, 2, 1] 🔹 Constraints: Solve in O(n) time Try both approaches: Using extra space (HashMap / Set) In-place (for sorted array – O(1) space) 💡 Challenge: Can you modify your solution to: 👉 Return only duplicate elements instead of unique ones? 🔗 GitHub Repository: https://lnkd.in/grtu5Us8 💬 Drop your approach in the comments 👇 Let’s learn together 🚀 #DSA #CodingPractice #JavaScript #InterviewPrep #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 1/75 Blind 75 DSA Challenge - Two Sum (LeetCode #1) Problem: Given [2,7,11,15] and target 9, return indices [0,1] Brute Force (O(n²)): Check every pair Optimal (O(n)): Hashmap stores target - nums[i] javascript function twoSum(nums, target) { const seen = {}; for(let i = 0; i < nums.length; i++) { let complement = target - nums[i]; if(seen[complement] !== undefined) { return [seen[complement], i]; } seen[nums[i]] = i; } } Key Learning: Hashmaps turn O(n²) → O(n). Dry-ran on paper: [3,2,4] target 6 → [1,2] Tracker: ✅ 1/75 problems Next: Arrays Day 2 tomorrow #DSA #LeetCode #Blind75 #JavaScript #InterviewPrep #Frontend
To view or add a comment, sign in
-
Still consistent with my DSA practice — focusing on core logic building. 🚀 Today I worked on: 🔹 Find Intersection of Two Arrays Problem: Given two arrays, find the common elements between them. Simple brute-force approach, but it clearly shows how nested loops and comparisons work. Yeah, this isn’t optimized — but right now I’m focusing on understanding logic first, optimization later. Because if your base is weak, no “optimized solution” will save you. #DSA #JavaScript #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
DSA session update — Strings and Time & Space Complexity! ✅ Strings in JavaScript Strings are everywhere in development — but I never truly studied them from a DSA perspective before. This time I went deep: 🔹 String traversal 🔹 Reverse, palindrome problems 🔹 Character frequency & counting 🔹 Substring problems 🔹 String comparison techniques Time & Space Complexity This is what separates a working solution from a good one. Writing code that runs is not enough — understanding how it scales is what really matters. 🔹 Big O Notation — O(1), O(n), O(n²), O(log n) 🔹 Time Complexity — how algorithm scales with input size 🔹 Space Complexity — how much memory your solution uses 🔹 Best, average & worst case analysis 🔹 Choosing the right tradeoffs for each problem What clicked for me — every decision I make while coding now has a cost. Knowing that cost is what makes you think like a real engineer, not just a developer. Alhamdulillah for every concept that deepens the foundation. 🚀 #JavaScript #DSA #Strings #TimeComplexity #SpaceComplexity #BigO #FrontEndDevelopment #InterviewPrep #LearningInPublic #CareerGrowth
To view or add a comment, sign in
-
-
📘 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐌𝐨𝐝𝐮𝐥𝐞 (𝐁𝐚𝐬𝐢𝐜) 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 7: 𝐒𝐭𝐫𝐢𝐧𝐠 1.What is string? 2.How to declare string? 3.String Declare Special way or Special purpose string? 4.String Check type? 5.String length Check? 6.String Access index? 7.What is empty string? 8.When to use empty string? 9.String is immutable or mutable? 10.String methods? 11.String concatenation? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.Difference between slice and substring? 2.What is template literal? 3.Why string is immutable? 4.What are the benefits of Template Literals (Backticks ``)? 5.Why are strings immutable in JavaScript? How does it work in memory? 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 8: 𝐍𝐮𝐦𝐛𝐞𝐫 & 𝐃𝐚𝐭𝐞 1.What is number? 2.Number Types? 3.Math methods? 4.How to find date? 5.Date methods? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.Difference between Math.floor and Math.round? 2.How to generate random number between range? #DotNet #AspNetCore #MVC #FullStack #SoftwareEngineering #ProgrammingTips #DeveloperLife #LearnToCode #JavaScript #JS #JavaScriptTips #JSLearning #FrontendDevelopment #WebDevelopment #CodingTips #CodeManagement #DevTools
To view or add a comment, sign in
-
-
Created a one-page cheat sheet for HTML input elements. Everything in one place: • Input types • Important attributes • Form example • Interview questions Keeping my fundamentals clear and revision quick. #WebDevelopment #FrontendDeveloper #HTML #Coding #TechJourney
To view or add a comment, sign in
-
-
📘 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐌𝐨𝐝𝐮𝐥𝐞 (𝐁𝐚𝐬𝐢𝐜) 𝐒𝐞𝐜𝐭𝐢𝐨𝐧 6: 𝐀𝐫𝐫𝐚𝐲 & 𝐋𝐨𝐨𝐩𝐬 🔹 𝐀𝐫𝐫𝐚𝐲 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 1.What is array / collection / list? Why use it? 2.Array syntax / How to declare an array? 3.What is array index? 4.Array index starts from? 5.How to access element? 6.How to set value? 7.Findout Array length / How to find total length? 8.Array methods? 9.What is array method? 10.Why use array method? 🔹 𝐋𝐨𝐨𝐩 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 1.What is loop? 2.Why use loop? 3.Loop structure? 4.Types of loop? 5.Array loop / Array specific loops? 6.Array is immutable or mutabl? 7.What is loop iteration? 8.Loop control statements? 9.What is array of object? 10.Why use array of object? 🎯 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 (𝐄𝐱𝐭𝐫𝐚) 1.What is the main difference between slice() and splice()? 1.What is the difference between map() and forEach()? (Which one should you use when?) 2.What is the difference between filter() and find()? (Which one should you use when?) 3.When to use reduce()? 4.Difference between for...in() and for...of()? #DotNet #AspNetCore #MVC #FullStack #SoftwareEngineering #ProgrammingTips #DeveloperLife #LearnToCode #JavaScript #JS #JavaScriptTips #JSLearning #FrontendDevelopment #WebDevelopment #CodingTips #CodeManagement #DevTools
To view or add a comment, sign in
-
-
Day 17 of #LeetCodeDaily Problem: Sort Colors (Medium) Given an array with values 0, 1, 2 representing colors (Red, White, Blue), sort them in-place without using any built-in sort. 🔍 My Approach: Use Dutch National Flag Algorithm (3-pointer approach) Maintain three pointers: low → position for 0 mid → current element high → position for 2 Algorithm: If element is 0 → swap with low, move both low & mid If element is 1 → just move mid If element is 2 → swap with high, move high only This ensures: Left side → all 0s Middle → all 1s Right side → all 2s ⏱ Time: O(n) 📦 Space: O(1) Single pass + in-place sorting makes it optimal 🚀 💡 Learning: When array has limited values → think partitioning Key insight → don’t move mid when swapping with high Always re-check swapped elements Classic problem to test pointer manipulation skills #ProblemSolving #LeetCode #JavaScript #DSA #Algorithms #Array #InterviewPrep #CodingJourney #30DaysDSAChallenge #LearningInPublic
To view or add a comment, sign in
-
-
💡 Quick JS Trick: Group Anagrams Want to group words that are anagrams of each other? Use sorting & a Map — super clean and efficient: ✅ How it works: 🔹 Sort letters in each word → same letters = same key. 🔹 Use a Map to group words by this key. 🔹 Return all grouped values. ✨ Benefits: ✅ Simple ✅ Fast ✅ Works for any list of strings #JavaScript #CodingTips #Algorithms #DataStructures #CleanCode #WebDevelopment #JSChallenge
To view or add a comment, sign in
-
-
Still consistent with my DSA practice — focusing on building strong logic step by step. 🚀 Today’s problem: 🔹 Check Perfect Square Problem: Determine whether a given number is a perfect square or not. Simple brute-force approach, but it builds a clear understanding of loops, conditions, and mathematical logic. Not everything needs to be optimized from day one. First, understand it. Then improve it. That’s the plan. #DSA #JavaScript #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development