Solved 3 out of 4 problems in today's LeetCode Weekly Contest 402! Question 1: I solved it simply using brute force: if (nums[i] + nums[j]) % 24 == 0, increase the count. Submission Link: https://lnkd.in/giV9CfV8 Question 2: Here, I utilized a hashMap to reduce the time complexity because my previous solution was O(N*N). However, in hurry, I received a penalty because I didn't notice the return type of the function (long). I mistakenly assumed it was the same return type as the previous problem (int). Submission Link: https://lnkd.in/gRYBpQj9 Question 3: I quickly realized this required a standard take or not take DP approach (as we can only take power[i] and not the remaining +-2), but implementing it took a long time. Submission Link: https://lnkd.in/g3BZCx7W Happy Coding! 💕 #Algorithm #CodingChallenge #CompetitiveProgramming #TechSolution #DataStructures #LeetCode #Programming #SoftwareDevelopment #ProblemSolving #TechEditorial #DynamicProgramming #CodingTips #SoftwareEngineering #TechCommunity #DevLife #TechSkills
Karan Shishodia’s Post
More Relevant Posts
-
🚀 𝗗𝗮𝘆 𝟯𝟬: Just tackled LeetCode Problem 74: 𝗦𝗲𝗮𝗿𝗰𝗵 𝗮 𝟮𝗗 𝗠𝗮𝘁𝗿𝗶𝘅, an interesting challenge involving a matrix search! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: You are given an 𝗺 𝘅 𝗻 integer matrix 𝗺𝗮𝘁𝗿𝗶𝘅 with the following two properties: 🔹 Each row is sorted in non-decreasing order. 🔹 The first integer of each row is greater than the last integer of the previous row. Given an integer target, return 𝘁𝗿𝘂𝗲 if target is in matrix or 𝗳𝗮𝗹𝘀𝗲 otherwise. I first checked the last element of each row to see if it’s equal to or greater than the target. If the last element was smaller, I skipped that row. Once I identified a potential row, I performed a linear search within that row to look for the target. This approach ensures we skip unnecessary rows and only search within relevant ones, making the solution efficient for reasonably sized matrices. 📍 Another step forward in strengthening my problem-solving skills! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #Search2DMatrix #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
#Day29: Successfully Solved 1 LeetCode Problems🚀 🎯 LeetCode Problem : Find and Replace Pattern (#890) Question: Given a list of strings words and a string pattern, return a list of all words that match the pattern. A word matches if there exists a one-to-one mapping of characters between the word and the pattern. Example 1: Input: words = ["abc", "deq", "mee", "aqq", "dkd", "ccc"], pattern = "abb" Output: ["mee", "aqq"] Explanation: "mee" matches because we can map {a -> m, b -> e}. "ccc" doesn't match because multiple characters map to the same letter. 💡 My Approach: 1️⃣ Used a helper function match() to check if a word follows the same pattern as pattern by creating a mapping of characters. 2️⃣ Checked both directions (word → pattern and pattern → word) to ensure a bijection (one-to-one and onto mapping). 3️⃣ For each word in the array, validated it using the helper function and added valid words to the result list. 📈 Time Complexity:O(n × m): 📊 Space Complexity: O(m): 📸 Here's a screenshot of my successful submission on LeetCode! 🎉 #LeetCode #CodingChallenge #ProblemSolving #Programming #JavaDevelopment #StringMapping #TechJourney #DevLife #CodingCommunity
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟳: Just solved LeetCode Problem 28: a string challenge to find the 𝗜𝗻𝗱𝗲𝘅 𝗼𝗳 𝗮 𝗦𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴’𝘀 𝗙𝗶𝗿𝘀𝘁 𝗢𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲 in a larger string! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given two strings 𝗻𝗲𝗲𝗱𝗹𝗲 and 𝗵𝗮𝘆𝘀𝘁𝗮𝗰𝗸, return the index of the first occurrence of needle in haystack, or -𝟭 if needle is not part of haystack. The task was to locate where one string (the needle) first appears in another string (the haystack). I used a straightforward iteration with the 𝘀𝘂𝗯𝗦𝘁𝗿() method to extract slices of the haystack string matching the length of the needle. Each slice was compared to the needle to check for a match, allowing me to efficiently locate the index of the first occurrence. If no match was found, the function returned -𝟭 as specified by the problem. 📍 Excited to continue tackling more problems and sharpening my skills one challenge at a time. Onward to the next! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #FindingIndex #FirstOccurance #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟴: Just solved LeetCode Problem 66: the famous one, 𝗣𝗹𝘂𝘀 𝗢𝗻𝗲! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: You are given a non-negative integer represented as a non-empty array of 𝗱𝗶𝗴𝗶𝘁𝘀, and you need to add 𝟭 to that number. The digits are stored in reverse order (from least significant to most significant), and the goal is to return the result as an array. Here’s how I approached this: • Since we need to add 1, start from the last element of the array. • If the digit is not equal to 9, just add 1 and return the array. • If the digit is 9, set it to 0 (carry over) and move to the next digit. • If we finish the array and still have a carry (like adding 1 to [9,9,9]), prepend a 1 to the result. 📍 Feeling accomplished after solving this. Let’s keep up the momentum and tackle more challenges! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #PlusOne #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟰: Just tackled LeetCode Problem 27: a classic challenge, 𝗥𝗲𝗺𝗼𝘃𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given an integer array 𝗻𝘂𝗺𝘀 and an integer 𝘃𝗮𝗹, remove all occurrences of 𝘃𝗮𝗹 in 𝗻𝘂𝗺𝘀 in-place. The relative order of the elements may be changed. I used a two-pointer technique to efficiently process the array, keeping track of elements that should remain. One pointer iterates through each element, while the other pointer helps overwrite positions where the target value is found, effectively "removing" elements in-place. This approach kept the solution fast and memory-efficient, as required by the problem constraints. 📍 Excited to keep growing my skills one problem at a time. LeetCode, bring on the next challenge! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #RemoveElement #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
Day 14: String and Integer Manipulation Today's LeetCode challenges covered a diverse range of problem-solving techniques. I tackled the "Longest Common Prefix" problem, which required efficient string comparison and pattern recognition. Additionally, I explored integer manipulation with the "Reverse Integer" challenge, focusing on handling potential overflow and negative numbers. A fulfilling day of coding and learning! Problem Links:- 14. Longest Common Prefix:- https://lnkd.in/gkdPnQj7 7. Reverse Integer:- https://lnkd.in/gYb9CNbN Github Repo:- https://lnkd.in/gjKwWR9k #100DaysOfCode #LeetCode #C++ #codingchallenge #day14 #strings #integers #algorithms #datastructures #softwareengineer #tech #learning #growth
To view or add a comment, sign in
-
🚀 Day 15 of #100DaysOfCode 🚀 Today, I discovered the Knuth-Morris-Pratt (KMP) algorithm while solving LeetCode's 214. Shortest Palindrome. The task involved transforming a string into a palindrome by adding characters at the front, and it was the perfect opportunity to explore KMP, which helps efficiently find occurrences in a string. ⛓️💥 This challenge reminded me of the importance of doing research when tackling problems, even ones that seem simple at first glance. It’s important to realize that while you may not know everything, someone has likely already developed a solution or algorithm that can help—research can be a powerful tool in problem-solving! 🔥 You can read more about KMP here: https://lnkd.in/dVer--CC Here’s a quick breakdown of my approach: * Created a combined string by concatenating the input with its reversed form. * Applied the KMP algorithm to compute the longest palindromic prefix. * Returned the shortest palindrome by adding the missing characters in front. 💻 Check out my #100DaysOfCode Repo: https://lnkd.in/dYXGbB5h 🔜 Tomorrow: As always one leetcode a day and I want to do some socket programming on the weekend too. Have you ever used KMP in your projects? Let’s connect and share insights! 😄 #TechJourney #100DaysOfCode #LeetCode #Algorithms #KMP #Cplusplus #Palindrome
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟮𝟱: Just solved LeetCode Problem 747: 𝗟𝗮𝗿𝗴𝗲𝘀𝘁 𝗡𝘂𝗺𝗯𝗲𝗿 𝗮𝘁 𝗟𝗲𝗮𝘀𝘁 𝗧𝘄𝗶𝗰𝗲 𝗼𝗳 𝗢𝘁𝗵𝗲𝗿𝘀, a fun problem that combines array traversal and conditional checks! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given an integer array 𝗻𝘂𝗺𝘀 where the largest integer is at least twice as much as every other number in the array. Determine whether this condition holds true. If it does, return the index of the largest number. Otherwise, return -𝟭. I looped through the array to identify the index of the largest number. Using a second loop, I compared the largest number with each element to ensure it was at least twice as large as all others. If any element violated this condition, I returned -1. If the checks passed, I returned the index of the dominant number. 📍 Feeling motivated to keep tackling more such problems! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #LargestNumber #TwiceOfOthers #Programming #DailyLearning #Developer #ProblemSolving
To view or add a comment, sign in
-
🚀 𝐃𝐚𝐲 𝟑𝟐 𝐨𝐟 𝟏𝟎𝟎 𝐃𝐚𝐲𝐬 LeetCode 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐢𝐧𝐠 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 🔍 Leetcode Challenge: 𝐄𝐯𝐚𝐥𝐮𝐚𝐭𝐞 𝐑𝐞𝐯𝐞𝐫𝐬𝐞 𝐏𝐨𝐥𝐢𝐬𝐡 𝐍𝐨𝐭𝐚𝐭𝐢𝐨𝐧 🔍 🔹 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: Given an array of strings representing an arithmetic expression in Reverse Polish Notation (RPN), evaluate the expression and return its integer value. Valid operators are '+', '-', '*', and '/'. Operands may be integers or other expressions, and division truncates toward zero. 🔹 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: 𝐒𝐭𝐚𝐜𝐤-𝐁𝐚𝐬𝐞𝐝 𝐄𝐯𝐚𝐥𝐮𝐚𝐭𝐢𝐨𝐧: Used a stack to store operands. 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐢𝐧𝐠 𝐓𝐨𝐤𝐞𝐧𝐬: Iterated through each token, pushing numbers onto the stack and applying operators by popping the required operands. 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬 𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠: Implemented addition, subtraction, multiplication, and division by popping operands, performing the operation, and pushing the result back onto the stack. 𝐑𝐞𝐬𝐮𝐥𝐭 𝐄𝐱𝐭𝐫𝐚𝐜𝐭𝐢𝐨𝐧: The final result was the last element remaining on the stack. 🔹 𝐎𝐮𝐭𝐜𝐨𝐦𝐞: Successfully evaluated RPN expressions in O(n) time complexity, ensuring correct handling of various operators and operand combinations. Submission Link:https://lnkd.in/gB9ZAk5N #coding #leetcode #problemsolving #programming #stack #datastructures
To view or add a comment, sign in
-
Let's Discuss LeetCode weekly contest 405. Q1. 3210. Find the Encrypted String. Approach:- Just understanding of modules operator easily done. Solution:- https://lnkd.in/gkrsy59p Q2. 3211. Generate Binary Strings Without Adjacent Zeros Approch:- Find all the substring and simply check not two adjacent zero occurs. Solution:- https://lnkd.in/g-s7nDpn Let's Discuss LeetCode Biweekly Contest 134. Q1.3206. Alternating Groups I Approch:- Simply using the loop count group and edge cases. Solution:- https://lnkd.in/gjjNXgZx Q2. 3207. Maximum Points After Enemy Battles Approch:- In this question we earn points only from the first number and use the another for increasing the enery. Solution:- https://lnkd.in/gnB9Qy8W Happy coding 😊 Follow:- KRISHNA NAND MISHRA #LeetCode #CodingChallenge #ContinuousLearning #ProblemSolving #TechSkills #Programming #Coding #CareerGrowth #KeepLearning #SoftwareEngineering #Google
To view or add a comment, sign in