LeetCode POTD: Minimum Difference Between Highest and Lowest K Scores Intuition: The goal is to pick k scores such that the difference between the maximum and minimum is minimized. After sorting the array, this becomes straightforward. For any window of size k: The maxi is at the right end - nums[i] The mini is at the left end - nums[i - k + 1] We slide this window across the array and keep updating the minimum difference. This works because sorting ensures elements inside each window are in ascending order. Time Complexity: O(n log n) The detailed thought process and example are explained in the notes below 👇 #leetcode #potd #problemsolving #coding #slidingwindow #twopointers #consistency
Minimize K Score Difference with LeetCode Sliding Window
More Relevant Posts
-
Day 19 Of #100DaysOfCode: #DSA: Solve leetcode problem with Merge Intervals Pattern - Insert Intervals(medium 57) Approach: - Sort the array by start time - create a temp vector/array - now iterate over intervals and check for each interval if its start time is greater then the newInterval start time if it is then add newInterval into the temp else add curr interval - now merge the intervals that are stored in temp vector/array Time Complexity: O(n logn) Space Complexity: O(n) #Coding #LearnInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 28 of #100DaysOfCode: #DSA: Solve leetcode problem - Longest Palindrome(409) A palindrome string can be even/odd length so if the frequencies of letters are: 1. Even - we can use all of them to create palindrome string 2. Odd: - we can use frequency - 1 witch becomes even - we can leave one character for the middle approach: - hashmap to track freq of letters - iterate to the string - if freq is even just add to result - if freq is odd then add (freq - 1) to result - now in the last check - if hashmap contains only even freq return result - else return (result + 1) for middle character #Coding #Learing #CodingJourney
To view or add a comment, sign in
-
-
TIL Emacs has code folding built in (of course it has!). Enable it with `hs-minor-mode` and toggle function, class or comment folding/unfolding with `hs-cycle`. There are many other commands to try too: `hs-hide-all`, `hd-show-all` and so on. Read more: https://lnkd.in/eR5dG7km #emacs #coding
To view or add a comment, sign in
-
-
Day 57 – Populating Next Right Pointers in Each Node 🌳🔗 I leveraged the perfect binary tree property to establish level links without using a queue. Starting at the root, I traversed level by level using the leftmost node, and for each node along the way, established connections between its children pointing the left child to the right child, and the right child to the next node's left child when available. This approach achieved O(n) time with O(1) space, demonstrating how tree traversal can be reimagined when additional pointers become part of the structure itself. By building connections iteratively, each level transforms into a linked list that guides the next, turning vertical depth into horizontal reach. #LeetCode #Coding #Algorithms #DataStructures #BinaryTree #TreeTraversal #Pointers #PerfectBinaryTree #ProblemSolving #SoftwareEngineering #Programming #100DaysOfCode
To view or add a comment, sign in
-
In Go, you can read from files, network connections, HTTP request bodies, and even strings using the same code. The secret is io.Reader. The io.Reader interface describes where data comes from, not how it is stored. If a type knows how to provide bytes when asked, it implements io.Reader. Your function accepts io.Reader, and suddenly it works everywhere. This is interface-based design in action. Your code depends on behaviour, not concrete types. Read once, use everywhere. Follow me for more Go bytes #golang #golangtips #goprogramming #coding #softwaredevelopment
To view or add a comment, sign in
-
-
Day 23 of #100DaysOfCode: #DSA: Stack: 1. Simple Stack 2. Monotonic stack: Stores items in sorted order(strictly increasing/decreasing) 3. Greedy Stack: pop/push based on greedy decisions to build an optimal result. Leetcode Problem: - Remove All Adjacent Duplicates(1047) approach: - use stack - assume first item is unique and add it to the stack - now iterate over the string - if stack top == current char then pop (it's adjacent and duplicate remove them) - else push current char - build final string from the stack and return it Time Complexity: O(n) Space Complexity: O(n) #Coding #CodingJourney
To view or add a comment, sign in
-
-
Day 14/45 of my DSA Challenge 🚀 Today's trio: LeetCode 34, 35, 704 - all about Binary Search variations! Here's what clicked for me: Binary Search isn't just about finding an element. It's about finding BOUNDARIES. 🎯 Quick question for fellow coders: What's trickier for you? 🔹 Getting the mid calculation right 🔹 Handling the left/right pointer updates 🔹 Edge cases (empty arrays, single elements) Drop your answer below! Let's learn from each other. Day 14 done. 31 more to go. The consistency is building momentum! 💪 #DSAChallenge #LeetCode #CodingJourney
To view or add a comment, sign in
-
Day 10 | DSA Journey Searching & Sorting basics — Linear Search, Binary Search, Bubble Sort, Selection Sort. Code and approach shared. Repo: https://lnkd.in/dbQVQeXw Akshay Saini 🚀 NamasteDev.com #DSA #CodingJourney #namastedsa #namastedev #coding #consistency
To view or add a comment, sign in
-
#Day502 of #600DaysOfDSA Topics and Learnings: #LinkedList, #2Pointers Problems Re-revised: 122. #LeetCode #19 : Remove Nth Node From End of List Approach: Used #TwoPointers to solve this Complexity Analysis: TC: O(N) SC: O(1) #600DaysLeetCodeChallenge #600DaysLeetCode #DataStructures #Algorithms #ProblemSolving #DSA #LeetCode #TakeUForward #TUF+ #SoftwareDevelopment #ContinuousLearning #ProfessionalGrowth #Coding
To view or add a comment, sign in
-
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
Great!