LeetCode POTD 💫: Description: You are given an array nums of n integers and two integers k and x. The x-sum of an array is calculated by the following procedure: -> Count the occurrences of all elements in the array. -> Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element with the bigger value is considered more frequent. -> Calculate the sum of the resulting array. Note that if an array has less than x distinct elements, its x-sum is the sum of the array. Return an integer array answer of length n - k + 1 where answer[i] is the x-sum of the subarray nums[i..i + k - 1]. Here's my solution: https://lnkd.in/gmUKJuq2 #Python #DSA #Leetcode #DailyChallenge #Hard
Hanni Kanchap’s Post
More Relevant Posts
-
LeetCode POTD 😁: Description: You are given an array nums of n integers and two integers k and x. The x-sum of an array is calculated by the following procedure: -> Count the occurrences of all elements in the array. -> Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element with the bigger value is considered more frequent. -> Calculate the sum of the resulting array. Note that if an array has less than x distinct elements, its x-sum is the sum of the array. Return an integer array answer of length n - k + 1 where answer[i] is the x-sum of the subarray nums[i..i + k - 1]. Here's my solution: https://lnkd.in/g6gjzEq7 #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
LeetCode POTD 💫: Description: Given an integer n, you must transform it into 0 using the following operations any number of times: -> Change the rightmost (0th) bit in the binary representation of n. -> Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0. Return the minimum number of operations to transform n into 0. (Big thanks to Mazhar Imam Khan for his clear and insightful video explanation — saw it just in time and it made all the difference 🙌) Here's my solution: https://lnkd.in/gTU_uPUd #Python #DSA #Leetcode #DailyChallenge #Hard #BitManipulation
To view or add a comment, sign in
-
-
69. Sqrt(x) Solved Easy Topics Companies Hint Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python. Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
To view or add a comment, sign in
-
-
🔷 Day 19- 30DaysChallenge(Leetcode Problem): Pascal's Triangle 🌟 Problem: Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly. 🧠Solution: class Solution: def generate(self, numRows: int) -> List[List[int]]: res=[[1]] for i in range(numRows-1): temp=[0]+res[-1]+[0] row=[] for j in range(len(res[-1])+1): row.append(temp[j]+temp[j+1]) res.append(row) return res #DSA #Python #CodingChallenge #30dayschallenge #Leetcode
To view or add a comment, sign in
-
🧩 Day 39 — Find First and Last Position of Element in Sorted Array (LeetCode 34) 📝 Problem -Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. -If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity 🔁 Approach -Use binary search twice — once to find the first occurrence and once to find the last occurrence. -For the first position: -When nums[mid] == target, move left (right = mid - 1) to continue searching earlier indices. -For the last position: -When nums[mid] == target, move right (left = mid + 1) to continue searching later indices. -If the target does not exist in the array, return [-1, -1] 📊 Complexity -Time Complexity: O(log n) -Space Complexity: O(1) 🔑 Concepts Practiced -Binary Search -Divide and Conquer -Edge Case Handling #Leetcode #Python #DSA #BinarySearch #Divide
To view or add a comment, sign in
-
-
Built a quick reference guide for RAG patterns. Spent some time documenting 5 common patterns I kept seeing in production systems: • Semantic chunking • HyDE (query expansion) • Re-ranking • Metadata filtering • Query decomposition Each one has working Python code and notes on when it's worth using vs. when it's overkill. Also threw in some case studies with actual numbers ($900K-$2.3M impact range) from real implementations I researched. Nothing groundbreaking - just a clean reference for the trade-offs (latency, cost, quality) since I couldn't find one that laid it out clearly. Live docs: https://lnkd.in/edsUB5mA Code: https://lnkd.in/e9Xqrme6 #MachineLearning #RAG #Python
To view or add a comment, sign in
-
🚀 Day 43 of #100DaysOfDSA 💡 Problem: 993. Cousins in Binary Tree 🔗 LeetCode: https://lnkd.in/djrWKuC4 🧠 Approach: - Used DFS to record the depth and parent of both target nodes (x and y). - Compared their depths and parents to check if they are cousins (same level, different parents). - Used recursion for clean and efficient traversal. 📚 Learnings: - Strengthened understanding of tree traversal using recursion. - Learned to track multiple attributes (depth, parent) simultaneously. - Improved logical reasoning for binary tree relationship problems. 👨💻 LeetCode Profile: https://lnkd.in/dGQwSXjb #100DaysOfDSA #Day43 #LeetCode #Python #BinaryTree #DFS #Recursion #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
How do you analyse outliers quickly? Here’s a simple way — from MGD_Outliers import OutlierNinja No need to manually calculate: - Quantile values - IQR - Upper & Lower bounds - Filter outliers based on upper and lower bound OutlierNinja fits directly on your data and gives you all these values pre-calculated. Your focus stays where it matters, i.e. analyzing and processing the outliers as per your use case. For a detailed walkthrough, check out this playlist: https://lnkd.in/d8TCaAyG Or check out PyPI documentation: https://lnkd.in/dUYQ2z6H How do you usually detect and handle outliers in your workflow? #datascience #dataanalyst #python #MachineLearning #DataCleaning #DataPreprocessing #OutlierDetection #CodingTips
To view or add a comment, sign in
-
🧩 Day 32 — Find the Difference of Two Arrays (LeetCode 2215) 📝 Problem Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: - answer[0] contains all distinct integers in nums1 not present in nums2. - answer[1] contains all distinct integers in nums2 not present in nums1. The order of elements in the output lists does not matter. 🔁 Approach - Use sets to eliminate duplicates and enable fast lookups. - Convert both arrays to sets: set1 and set2. - Compute differences using set operations: - set1 - set2 gives elements in nums1 not in nums2. - set2 - set1 gives elements in nums2 not in nums1. - Convert the results back to lists to match the required output format. 📊 Complexity - Time Complexity: O(n + m) - Space Complexity: O(n + m) 🔑 Concepts Practiced - Set operations for fast difference computation - Removing duplicates using set() - Efficient list transformation - Clean and readable Python logic #Python #DSA #Leetcode #ProblemSolving #Arrays
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
Awesome