Day 67 of 365 Days of code the infamous brainrot number Qn 1) Reorder list You are given the head of a singly linked-list. The positions of a linked list of length = 7 for example, can intially be represented as: [0, 1, 2, 3, 4, 5, 6] Reorder the nodes of the linked list to be in the following order: [0, 6, 1, 5, 2, 4, 3] Notice that in the general case for a list of length = n the nodes are reordered to be in the following order: [0, n-1, 1, n-2, 2, n-3, ...] You may not modify the values in the list's nodes, but instead you must reorder the nodes themselves. approach: use 5 pointers(scary :")) #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
Reorder Linked List Nodes
More Relevant Posts
-
Day 71 of 365 Days of code qn 1) koko eats banana approach: binary search 1) set low=1 and high= max(piles) 2) find mid=low+(high-low) 3) traverse the entire array and check if the number of hours taken by the current rate of consumption is less than the threshold hours if yes set high=mid-1 4) else low=mid+1 #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
LeetCode POTD 💫: Description: A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows. originalText is placed first in a top-left to bottom-right manner. encodedText is then formed by appending all characters of the matrix in a row-wise fashion. Given the encoded string encodedText and number of rows rows, return the original string originalText. Note: originalText does not have any trailing spaces ' '. The test cases are generated such that there is only one possible originalText. Here's my solution: https://lnkd.in/g2EMmfzE #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
LeetCode 23: Merge k sorted list: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Approach: Simple and straightforward, iterate through each of the linked-list in the given list, push each node's value into a priority queue using heapq module, create a new linked-list using the elements of priority queue. Time complexity: O(n logn) where n is the total number of values. Space complexity: O(n) #Python #LeetCode #DSA #CompetitiveProgramming #DataStructures #Algorithms #ProblemSolving
To view or add a comment, sign in
-
-
Day 3 of #50DaysDSA Problem Solved: Reverse Vowels of a String Today’s problem focused on efficient string manipulation using the two-pointer technique, a fundamental approach in algorithm design. Problem Statement: Given a string, reverse only the vowels while keeping all other characters in their original positions. Approach: Used two pointers (start and end) to traverse the string Identified vowels using a set for constant-time lookup Swapped vowels in-place while skipping non-vowel characters Continued until both pointers met Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) (due to string-to-list conversion in Python) Key Takeaway: This problem reinforces how a well-applied two-pointer strategy can lead to clean and optimal solutions without unnecessary data structures. #DSA #DataStructures #Algorithms #Python #SoftwareDevelopment #CodingPractice #Leetcode75 LeetCode Dhanraj Sahu
To view or add a comment, sign in
-
-
LeetCode Problem 3070: "Count submatrices with top left element and sum less than k": You are given a 0-indexed integer matrix grid and an integer k. Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k. Approach: use Prefix sum to calculate the total value of submatrix including the top left element upto a given cell. This approach is optimal and straightforward. #Python #DSA #LeetCode #ProblemSolving #CompetitiveProgramming #DailyCoding
To view or add a comment, sign in
-
-
Ask Claude to refactor a module. It reads related files. Checks tests. Updates imports. Things you never asked for. How does it decide what to do next? Give it a tool called schedule_followup(). It looks like any other tool. But the side effect is — a new task enters the queue. The agent doesn't know it's planning. It's just calling a tool. Sound familiar? (That's lesson 6 all over again.) An outer loop drains the queue. A budget stops it from running forever. That's CrewAI delegation in 10 lines. Checkout the video. Day 8 of 9. One more to go. https://lnkd.in/g-YiAgtE #AIAgents #BuildInPublic #Python #LLM
To view or add a comment, sign in
-
🚀 Day 75 of #100DaysOfCode 🔥 LeetCode 179 – Largest Number 💡 Problem: Given a list of non-negative integers, arrange them such that they form the largest possible number. 🧠 Key Insight: Normal sorting won't work here ❌ We need a custom comparator based on string concatenation. 👉 Compare: - ""a + b"" vs ""b + a"" - Whichever gives a larger value should come first. ⚙️ Approach: 1. Convert numbers to strings 2. Sort using custom comparison logic 3. Join the result 4. Handle edge case (like "[0,0] → "0"") ⚡ Complexity: - Time: O(n log n) - Space: O(n) 🎯 Result: ✅ Accepted ⚡ Runtime: 0 ms (100%) 📌 Lesson Learned: Sometimes sorting logic depends on combination, not value. #LeetCode #Python #CodingJourney #DSA #100DaysOfCode #Sorting #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode POTD 💫: Trying to be consistent with POTDs 🫠 Description: You are given two strings, str1 and str2, of lengths n and m, respectively. A string word of length n + m - 1 is defined to be generated by str1 and str2 if it satisfies the following conditions for each index 0 <= i <= n - 1: -> If str1[i] == 'T', the substring of word with size m starting at index i is equal to str2, i.e., word[i..(i + m - 1)] == str2. -> If str1[i] == 'F', the substring of word with size m starting at index i is not equal to str2, i.e., word[i..(i + m - 1)] != str2. Return the lexicographically smallest possible string that can be generated by str1 and str2. If no string can be generated, return an empty string "". Here's my solution: https://lnkd.in/g6B2-GWz #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
Day 2 of my LeetCode journey 🚀 Today’s problem: Group Anagrams This challenge was all about grouping strings that share the same characters. I approached it using a dictionary + hashing strategy in Python. For each word, I sorted its characters and used that as a key (converted into a tuple), ensuring all anagrams map to the same bucket. Here’s the core logic I implemented: ▪️Traverse the list of strings ▪️Sort each string → convert to tuple → use as dictionary key ▪️Append original string to the corresponding group ▪️Finally, return all grouped values This approach keeps the implementation clean and scalable. Time Complexity: ▪️Sorting each string takes O(k log k) (where k = length of string) ▪️For n strings → O(n * k log k) overall Space Complexity: ▪️O(n * k) for storing grouped anagrams A solid step forward in understanding how hashing + transformations can simplify complex grouping problems. Staying consistent and leveling up daily 💪 #LeetCode #Day2 #Python #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 41/100 – #100DaysOfCode 🚀 Solved LeetCode #2529 – Maximum Count of Positive Integer and Negative Integer (Python). Today I practiced simple counting logic to determine whether positive or negative numbers are more in the array. Approach: 1) Initialize two counters: neg = 0 and pos = 0. 2) Traverse the array element by element. 3) If the number is negative, increment neg. 4) If the number is positive, increment pos. 5) Return the maximum of neg and pos. Time Complexity: O(n) Space Complexity: O(1) Strengthening fundamentals with simple counting techniques 💪 #LeetCode #Python #DSA #Arrays #ProblemSolving #100DaysOfCode
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