Some algorithms just feel smart the moment you learn them. For me, it was the Difference Array Technique ⚡ Why? • Simple to implement • Easy to visualize • Extremely useful in contests Classic use case: You are given q queries of type [l, r, x] → Add x to every element from index l to r. Brute force works. But with large constraints? Too slow. Difference Array optimizes this beautifully using only boundary updates + prefix sums. Small idea. Huge optimization. Good LeetCode problems for this pattern 👇 • Car Pooling https://lnkd.in/gRviAhhA • Corporate Flight Bookings https://lnkd.in/gCUg6whZ • Shifting Letters II https://lnkd.in/g2SbPQT3 #DSA #Algorithms #LeetCode #CompetitiveProgramming
Ayush Malik’s Post
More Relevant Posts
-
I begin my exploration of the #clanguage ctype functions with two of the most popular: toupper() and tolower(). These are also the only ctype functions that modify single characters. Bonus: I show one way to emulate these functions. Yes, it's the easy way. The hard way I do next week. https://lnkd.in/gsNAaw6e
To view or add a comment, sign in
-
DSA Patterns - Two Pointer Strategy Two Pointers might be the highest ROI DSA pattern to learn before your next interview. One pattern. Six problem types. Covers Pair Sum, Triplet Sum, Palindrome Validation, Largest Container, Shift Zeros, and Next Lexicographical Sequence. I just published a deep dive on Medium that breaks down: ✅ The 3 traversal strategies and when to use each ✅ Pseudocode for every algorithm ✅ Flowcharts so the logic clicks visually ✅ The naive approach vs the optimal two-pointer approach side by side This is part of an ongoing DSA Patterns series — built for engineers who want to stop memorizing solutions and start recognizing patterns. Full article⬇️ . If this helped, a repost goes a long way 🙏 https://lnkd.in/g6MvGfxR #DSA #TwoPointers #LeetCode #AlgorithmsAndDataStructures #SoftwareEngineering #CodingInterview #TechCareers #Python Mouser Electronics Microsoft CSharpCorner Developrs Group (DG) Silicon Valley
To view or add a comment, sign in
-
🚀 𝐂𝐨𝐦𝐩𝐞𝐭𝐢𝐭𝐢𝐯𝐞 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 | 𝐇𝐚𝐬𝐡𝐢𝐧𝐠 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞 + 𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐜𝐲 𝐌𝐚𝐩 | 𝐂𝐨𝐮𝐧𝐭 𝐍𝐮𝐦𝐛𝐞𝐫 𝐨𝐟 𝐏𝐚𝐢𝐫𝐬 𝐖𝐢𝐭𝐡 𝐀𝐛𝐬𝐨𝐥𝐮𝐭𝐞 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞 𝐊 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Count Number of Pairs With Absolute Difference K Given an integer array nums and an integer k, we need to count the number of pairs (i, j) such that: i < j |nums[i] - nums[j]| == k At first glance, a brute-force solution using nested loops seems straightforward, but it results in O(n²) time complexity, but it is not efficient for larger constraints. 💡 𝐎𝐩𝐭𝐢𝐦𝐚𝐥 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐔𝐬𝐢𝐧𝐠 𝐇𝐚𝐬𝐡𝐢𝐧𝐠 To optimize the solution, I used a Hash Map / Frequency Map approach. ✅ Key Idea: While traversing the array: Check whether (currentElement - k) already exists. Check whether (currentElement + k) already exists. Add their frequencies to the answer. Store/update the current element frequency in the hash map. ⚡ Time Complexity O(n) — Single traversal using hashing. ⚡ Space Complexity O(n) — For storing frequencies in the hash map. 🧠 Concepts Used ✔️ Hashing ✔️ Frequency Map ✔️ Array Traversal ✔️ Optimization from Brute Force to Optimal 🔗 Optimal Approach Code Link 👉 https://lnkd.in/gBe4ubet ------- I post DSA problems (1x daily) Hit the 🔔 icon → Select “𝐀𝐥𝐥” to get the link first Follow ( Krupesh Patil ) 💙 Like | ♻️ Repost | 💬 Comment ------- #CompetitiveProgramming #DSA #Hashing #Cpp #Programming #Coding #ProblemSolving #DataStructures #Algorithms #FrequencyMap #SoftwareEngineering
To view or add a comment, sign in
-
-
Don't get us wrong, but even in the world of AI and AI agents, we need to talk about things like C++ Coroutines. Lieven De Cock will be given a talk about it on our Dutch C++ Meetup in June. Join us! --> https://lnkd.in/eFCgmfYH What do you know about a Coroutine? A function you can pause and resume — simple concept, tricky in practice. We'll explore coroutines from two angles: user code and the compiler. What each side needs, where they meet, and how to glue them together. Topics covered: coroutine frames, handles, promise_type, awaiters, awaitables, and the full API. #CPP #meetup #softwaredevelopment
To view or add a comment, sign in
-
-
🚀 𝐇𝐚𝐬𝐡𝐢𝐧𝐠 + 𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐜𝐲 𝐂𝐨𝐮𝐧𝐭 = 𝐏𝐨𝐰𝐞𝐫𝐟𝐮𝐥 𝐒𝐭𝐫𝐢𝐧𝐠 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐢𝐧𝐠 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞 𝐢𝐧 𝐂𝐨𝐦𝐩𝐞𝐭𝐢𝐭𝐢𝐯𝐞 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 📌 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Given an array of strings, return all characters that appear in every string, including duplicates. Example: Input: ["bella","label","roller"] Output: ["e","l","l"] 🔍 𝐎𝐩𝐭𝐢𝐦𝐚𝐥 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 (𝐇𝐚𝐬𝐡𝐢𝐧𝐠 + 𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐜𝐲 𝐂𝐨𝐮𝐧𝐭): Instead of comparing every character manually between strings, we use: ✅ Frequency Map (Hashing) ✅ Minimum Frequency Tracking ✅ Character-wise Processing from 'a' to 'z' 💡 Core Idea: Count frequency of each character in every word. Maintain the minimum occurrence of every character across all words. The minimum frequency tells how many times a character should appear in the final answer. ⚡ Why This Approach is Efficient? ✔ Avoids unnecessary comparisons ✔ Works efficiently even for larger inputs ✔ Uses constant alphabet size (26 lowercase letters) ⏱ Time Complexity: O(N * L) Where: N = number of words L = average length of each word Since alphabet size is fixed (26), the solution remains highly optimized 🚀 🧠 𝐊𝐞𝐲 - 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: This problem is a great example of: Hashing Frequency Counting String Processing Minimum Frequency Logic Efficient Data Structure Usage 🔗 Code Link: https://lnkd.in/gqnyiFVJ #CompetitiveProgramming #DSA #Hashing #Cpp #Coding #ProblemSolving #Algorithms #Programming #Codeforces #DataStructures #SoftwareEngineering #Coding #Strings
To view or add a comment, sign in
-
-
Stop scrolling and start sorting. 📊 Sorting algorithms are more than just interview trivia—they are the building blocks of efficient engineering. I’ve put together a visual breakdown of 9 essential algorithms to help you master the logic in seconds. Save this list for your next study session! The Fundamentals (O(n^2)) 🔹 Bubble Sort: https://lnkd.in/gyPt5Kx8 🔹 Selection Sort: https://lnkd.in/gAAVi9kT 🔹 Insertion Sort: https://lnkd.in/gatVY6yh The Production Workhorses (O(n \log n)) 🚀 Quick Sort: https://lnkd.in/ggKRukfx 🚀 Merge Sort: https://lnkd.in/gezvwHAu 🚀 Heap Sort: https://lnkd.in/g9shTZuD The Linear Scalers (Specialized) ⚡ Counting Sort: https://lnkd.in/gY_8kADY ⚡ Bucket Sort: https://lnkd.in/g5y6x3iY ⚡ Radix Sort: https://lnkd.in/gNhY4-Pp The secret to being a great engineer isn't just knowing how to code these—it's knowing which one to pick for the right job. Which sorting algorithm was the hardest for you to master? Let’s discuss below! 👇 #SoftwareEngineering #ComputerScience #CodingInterviews #Algorithms #LearningToCode
#76 Radix Sort in 20s! | Day 9: 15-Day DSA Challenge #coding #shorts #ytshorts #inteviewtechbytes
https://www.youtube.com/
To view or add a comment, sign in
-
🚀 ���𝐨𝐦𝐩𝐞𝐭𝐢𝐭𝐢𝐯𝐞 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 | 𝐄𝐟𝐟𝐢𝐜𝐢𝐞𝐧𝐭 𝐇𝐚𝐬𝐡𝐢𝐧𝐠 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 | 𝐊-𝐃𝐢𝐟𝐟 𝐏𝐚𝐢𝐫𝐬 𝐢𝐧 𝐚𝐧 𝐀𝐫𝐫𝐚𝐲💡 🧠 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Given an integer array nums and an integer k, find the total number of unique pairs such that: [|nums[i] - nums[j]| = k] where: i != j Only unique pairs should be counted. 📌 Example: Input: nums = [3,1,4,1,5], k = 2 Output: 2 Valid pairs: (1,3) (3,5) ⚡ 𝐎𝐩𝐭𝐢𝐦𝐚𝐥 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 (𝐇𝐚𝐬𝐡𝐢𝐧𝐠) Instead of checking every pair using brute force O(n²), we can: 1️⃣ Store frequency of every element in an unordered_map. 2️⃣ Traverse the map: If k == 0, check elements having frequency > 1. Otherwise, check whether (current_element + k) exists in the map. 3️⃣ Count only unique valid pairs. ⏱️ Complexity Analysis Time Complexity: O(n) average Space Complexity: O(n) 🔗 Optimal Approach Code: https://lnkd.in/gm63ATx7 💡 Key Learning from this Problem ✅ Frequency maps help avoid duplicate pair counting. ✅ Hashing reduces unnecessary nested loop comparisons. ✅ Special handling is required when k = 0. ✅ Excellent problem to strengthen concepts of: Hash Maps Frequency Counting Unique Pair Logic ------- I post DSA problems (1x daily) Hit the 🔔 icon → Select “All” to get the link first Follow ( Krupesh Patil ) 💙 Like | ♻️ Repost | 💬 Comment ------- 🏷️ #CompetitiveProgramming #DSA #Hashing #Cpp #LeetCode #Coding #ProblemSolving #Algorithms #DataStructures
To view or add a comment, sign in
-
-
Most engineers solve this in O(n²). The best solve it in O(n + k). Same result. 🧠 Here is why the difference matters. 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗶𝗻 𝗼𝗻𝗲 𝗹𝗶𝗻𝗲: Given [8, 1, 2, 2, 3] → for each number, how many others are smaller? Answer: [4, 0, 1, 1, 2] 𝗡𝗮𝗶𝘃𝗲 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — O(n²): Compare every number against every other number. Works. But slow. 𝗦𝗺𝗮𝗿𝘁 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — O(n + k): ① Count how many times each number appears ② Build a running total (prefix sum) ③ For any number n → prefix sum at n-1 = count of smaller numbers No repeated comparisons. Each answer in O(1). 𝗧𝗵𝗲 𝗽𝗮���𝘁𝗲𝗿𝗻 𝘁𝗼 𝗿𝗲𝗺𝗲𝗺𝗯𝗲𝗿: Whenever values fall in a small bounded range → frequency array + prefix sum beats brute force every time. Same idea powers counting sort, bucket sort and range queries. Full C++ solution in the comments 👇 I mapped this as a visual card — check it out at www.interviewmapsai.com Follow Interview Maps AI for your daily interview map 🗺️ 🔗 www.interviewmapsai.com 📸 https://lnkd.in/gXt9hUrY ▶️ https://lnkd.in/gdsnyQZA 💼 https://lnkd.in/gxrW7-Q6 #SoftwareEngineering #CodingInterview #DSA #CPlusPlus #TechCareer
To view or add a comment, sign in
-
-
As we wrap up the week, we wanted to share something pretty cool you can do now in BlinqIO, and it’s worth trying. 👀 With Full AI Chat for Step Authoring and Verification, you can automate Playwright steps by typing what you want in plain English. Tell the AI what to do, like clicking a button, checking text, verifying a page title, or validating a URL, and it generates the Gherkin step name and Playwright code for you. Then you can watch it run live in the browser preview right away. You can also give multi-action instructions, and BlinqIO will split them into clean, separate steps automatically. Need more context? Upload a spec, user story, or document and let AI use it to help generate better steps. Less manual scripting. Faster feedback. Real Playwright code. 🎥 Watch the full video and see it in action. https://lnkd.in/eDAW5sYJ
2 Creating your first test
https://www.youtube.com/
To view or add a comment, sign in
-
"Agents are just LLM + loop + tools" - built with MATLAB + a local LLM. The core part is just a few lines of code: chat = openAIChat(systemPrompt, Tools=tools); % configure the LLM messages = messageHistory; % conversation history while true % agentic loop [text, response] = generate(chat, messages); % call the LLM messages = addResponseMessage(messages, response); if isempty(text) results = run_tools(response); % execute requested tools messages = addToolMessage(messages, results); else disp(text); % no more tool calls - done break end end
To view or add a comment, sign in