### Install Algo Sensei for Claude Code Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Commands to clone the repository and install the skill into either personal or project-specific directories. ```bash # Clone the repository git clone https://github.com/karanb192/algo-sensei.git # Copy to your personal Claude skills directory cp -r algo-sensei ~/.claude/skills/ # Restart Claude Code ``` ```bash # Clone the repository git clone https://github.com/karanb192/algo-sensei.git # Copy to your project's Claude skills directory cp -r algo-sensei /path/to/your/project/.claude/skills/ # Commit to git so your team gets it too! git add .claude/skills/algo-sensei git commit -m "Add Algo Sensei skill for DSA practice" ``` -------------------------------- ### Example Teaching Template Source: https://github.com/karanb192/algo-sensei/blob/main/modes/tutor-mode.md A structured template for explaining LeetCode problems, covering core task, walkthrough, pattern recognition, implementation, and complexity analysis. ```markdown Problem: [Problem Name]  Core Task: [Explain in simple terms]  Example Walkthrough: Input: [example] Let's trace through this step-by-step: 1. [step] 2. [step] Output: [result]  Pattern Recognition: This is a [pattern] problem because [reason]  Key Insight: [The "aha!" moment that makes this click]  Building the Solution: Pseudocode: [high-level logic] Python Implementation: [code with detailed comments]  Complexity: Time: O(?) because [explanation] Space: O(?) because [explanation]  Practice Problems: Try these similar problems: - [LeetCode #XXX] - [LeetCode #YYY] ``` -------------------------------- ### Array Visualization Example Source: https://github.com/karanb192/algo-sensei/blob/main/modes/tutor-mode.md An ASCII diagram illustrating an array with pointers to the left and right boundaries. ```text Array: [1, 3, 5, 7, 9] ^ ^ left right ``` -------------------------------- ### Get Hints on a Problem Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Use this prompt to receive progressive hints for a specific coding problem. Algo Sensei will automatically switch to Hint Mode. ```text You: "I'm stuck on LeetCode #3 - Longest Substring Without Repeating Characters. Can you give me a hint?" Algo Sensei: [Automatically switches to Hint Mode] πŸ’‘ Hint #1: What if you needed to track which characters you've seen recently? ... ``` -------------------------------- ### Refactoring for Readability Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Example of improving code readability by using descriptive function and variable names. ```python # ❌ Bad def f(a): r = [] for i in range(len(a)): if a[i] % 2 == 0: r.append(a[i]) return r # βœ… Better def filter_even_numbers(numbers): return [num for num in numbers if num % 2 == 0] ``` -------------------------------- ### Two Sum Optimization: Eliminating Redundant Comparisons Source: https://context7.com/karanb192/algo-sensei/llms.txt This code snippet shows an optimization for the Two Sum problem by adjusting the inner loop to avoid redundant comparisons. Instead of checking all pairs, it starts the inner loop from `i + 1` to only consider unique pairs. ```python # Instead of: # for j in range(len(nums)): # Use: for j in range(i + 1, len(nums)): ``` -------------------------------- ### Interview Introduction Script Source: https://github.com/karanb192/algo-sensei/blob/main/modes/interview-mode.md Use this script to initiate the interview process and set expectations for the candidate. ```text "Hi! I'm [name], senior engineer at [company]. Today we'll work through a coding problem together. I'm interested in your thought process, so please think out loud as you work. Feel free to ask clarifying questions. Ready? Let's get started." ``` -------------------------------- ### Review Your Code Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Submit your code solution for review. Algo Sensei will enter Review Mode to provide feedback. ```text You: "Here's my solution for Two Sum. Can you review it?" [paste code] Algo Sensei: [Automatically switches to Review Mode] πŸ” Code Review: Two Sum ... ``` -------------------------------- ### Algo Sensei File Structure Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Overview of the project's directory structure, including main files and subdirectories for different modes and templates. ```tree algo-sensei/ β”œβ”€β”€ SKILL.md # Main skill file (intelligent router) β”œβ”€β”€ README.md # You are here β”œβ”€β”€ modes/ β”‚ β”œβ”€β”€ tutor-mode.md # Concept explanations β”‚ β”œβ”€β”€ hint-mode.md # Progressive hints β”‚ β”œβ”€β”€ review-mode.md # Code review β”‚ β”œβ”€β”€ interview-mode.md # Mock interviews β”‚ └── pattern-mapper-mode.md # Pattern recognition β”œβ”€β”€ templates/ β”‚ └── solutions/ β”‚ └── solution-template.md # Multi-language solution format β”œβ”€β”€ scripts/ β”‚ └── [future: test generators, complexity analyzers] └── docs/ └── dsa-cheatsheet.md # Quick reference ``` -------------------------------- ### Practice Interview Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Initiate a mock interview session by requesting a problem of a specific difficulty. Algo Sensei will enter Interview Mode. ```text You: "Can we do a mock interview with a medium-level problem?" Algo Sensei: [Automatically switches to Interview Mode] 🎀 Hi! I'm Alex, senior engineer at TechCo. Ready to start? ... ``` -------------------------------- ### Learn a Concept Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Prompt Algo Sensei to explain a concept, such as dynamic programming. The tool will enter Tutor Mode for a structured explanation. ```text You: "Can you explain dynamic programming to me?" Algo Sensei: [Automatically switches to Tutor Mode] πŸ“š Let's build your understanding of DP from the ground up... ``` -------------------------------- ### Action Items and Learning Resources Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Structure review feedback with clear action items, learning resources, and a rating system. This provides a concise summary of the review and directs the learner's future efforts. ```markdown ### 🎯 Action Items 1. [Most important fix] 2. [Second priority] 3. [Nice to have] ### πŸ“š To Learn More - Study: [relevant pattern/concept] - Practice: [similar LeetCode problems] ### ⭐ Rating Correctness: [X/5] Efficiency: [X/5] Code Quality: [X/5] Interview Ready: [X/5] Overall: [Excellent/Good/Needs Work] ``` -------------------------------- ### Testing Guidance Template Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Provide a template for suggesting test cases, covering basic, edge, and special cases. This encourages thorough testing and consideration of various scenarios. ```markdown πŸ§ͺ Test Your Solution With: Basic Cases: - [example input] β†’ [expected output] Edge Cases: - Empty input: [] - Single element: [x] - All same: [1,1,1,1] - Maximum size: [array of 10^5 elements] Special Cases: - [problem-specific edge cases] ``` -------------------------------- ### Utilize Heapq for Min-Heap Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Standard library for priority queue operations. Negate values to simulate a max-heap. ```python import heapq heap = [] heapq.heappush(heap, item) smallest = heapq.heappop(heap) heapq.heapify(list) # Convert list to heap # Max heap: negate values heapq.heappush(heap, -item) ``` -------------------------------- ### Review Template Structure Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md A markdown-based template for providing structured feedback on algorithmic problems. ```markdown ## Code Review: [Problem Name] ### βœ… What Works Well [List 2-3 positive aspects] ### πŸ› Correctness Issues [If any - be specific about what fails and why] ### ⚑ Complexity Analysis **Your Solution:** - Time: O(?) - [explain why] - Space: O(?) - [explain why] **Optimal:** - Time: O(?) - Space: O(?) [If not optimal, explain the gap] ### πŸ’‘ Optimization Opportunities [Numbered list of improvements, each with explanation] ### πŸ“ Code Quality Feedback [Readability, style, best practices] ### 🎯 Suggested Improvements [Provide improved version with explanations] ### πŸ§ͺ Edge Cases to Test [List cases they should verify] ### πŸ’¬ Interview Tips [What to say when presenting this solution] ``` -------------------------------- ### Optimal Solution Implementations Source: https://github.com/karanb192/algo-sensei/blob/main/templates/solutions/solution-template.md Standardized function signatures for optimal solutions across multiple programming languages. ```python def optimal_solution(input_param): """ Brief description of approach """ # Initialize variables result = None # Main logic with comments # ... return result ``` ```javascript function optimalSolution(inputParam) { // Brief description of approach // Initialize variables let result = null; // Main logic with comments # ... return result; } ``` ```java class Solution { public ReturnType optimalSolution(InputType inputParam) { // Brief description of approach // Initialize variables ReturnType result = null; // Main logic with comments // ... return result; } } ``` ```cpp class Solution { public: ReturnType optimalSolution(InputType inputParam) { // Brief description of approach // Initialize variables ReturnType result; // Main logic with comments // ... return result; } }; ``` ```go func optimalSolution(inputParam InputType) ReturnType { // Brief description of approach // Initialize variables var result ReturnType // Main logic with comments // ... return result } ``` -------------------------------- ### Identify Pattern Source: https://github.com/karanb192/algo-sensei/blob/main/README.md Ask for help identifying an approach for a problem. Algo Sensei will switch to Pattern Mapper Mode to assist. ```text You: "I'm not sure what approach to use for this problem..." Algo Sensei: [Automatically switches to Pattern Mapper Mode] πŸ—ΊοΈ Let me help you identify the pattern... ``` -------------------------------- ### Optimizing List Lookups Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Demonstrates replacing O(nΒ²) list lookups with O(n) set operations for better performance. ```python # ❌ O(nΒ²) - checking if item in list repeatedly result = [] for item in items: if item not in result: # O(n) lookup each time! result.append(item) # βœ… O(n) - using set result = list(set(items)) # or if order matters: seen = set() result = [x for x in items if not (x in seen or seen.add(x))] ``` -------------------------------- ### Breadth-First Search (BFS) Queue Template Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md An iterative implementation of Breadth-First Search using a queue. Useful for finding shortest paths in unweighted graphs and level-order traversals. Requires a `visited` set. ```python from collections import deque queue = deque([start]) visited = {start} while queue: node = queue.popleft() for neighbor in graph[node]: if neighbor not in visited: visited.add(neighbor) queue.append(neighbor) ``` -------------------------------- ### Optimal Sliding Window Solution Source: https://context7.com/karanb192/algo-sensei/llms.txt An optimized sliding window approach with O(n) time complexity. ```python # O(n) - Single pass with window def optimal(arr, k): window_sum = sum(arr[:k]) max_sum = window_sum for i in range(k, len(arr)): window_sum += arr[i] - arr[i-k] # Slide window max_sum = max(max_sum, window_sum) return max_sum ``` -------------------------------- ### Handling Empty Input Edge Cases Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Shows how to safely handle empty input arrays to prevent runtime errors. ```python # ❌ Crashes on empty input def find_max(arr): return max(arr) # What if arr is []? # βœ… Handles edge case def find_max(arr): if not arr: return None # or raise ValueError return max(arr) ``` -------------------------------- ### Utilize Python Collections Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Common data structures for frequency counting, default dictionary values, and double-ended queues. ```python from collections import Counter, defaultdict, deque # Counter: frequency counting count = Counter([1,2,2,3]) # {1:1, 2:2, 3:1} # defaultdict: default values graph = defaultdict(list) # deque: double-ended queue queue = deque([1,2,3]) queue.append(4) # Add right queue.appendleft(0) # Add left queue.pop() # Remove right queue.popleft() # Remove left ``` -------------------------------- ### Improvement Path Structure Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Use this structure to show the progression from a brute-force solution to an optimal one, explaining the benefits of each step. This helps learners understand algorithmic complexity and optimization techniques. ```markdown **Your Solution (Brute Force):** O(nΒ²) [their code] **First Improvement (Hash Map):** O(n) [better approach] Why this works: [explanation] **Optimal Solution (Two Pointer):** O(n) time, O(1) space [optimal approach] Why this is better: [explanation] ``` -------------------------------- ### Brute Force Approach Template Source: https://github.com/karanb192/algo-sensei/blob/main/templates/solutions/solution-template.md A placeholder for the initial, straightforward, but potentially inefficient solution. ```text // Straightforward but inefficient approach // Code in user's preferred language ``` -------------------------------- ### Candidate Hinting Strategies Source: https://github.com/karanb192/algo-sensei/blob/main/modes/interview-mode.md Scripts for providing tiered hints when a candidate is stuck during the problem-solving phase. ```text "Let me give you a hint - think about [gentle nudge]" ``` ```text "What if you used a [data structure] to track [something]?" ``` ```text "Let me outline the approach: [high-level steps]. Can you implement this?" ``` -------------------------------- ### Interview Simulation Review Structure Source: https://github.com/karanb192/algo-sensei/blob/main/modes/review-mode.md Use this template for feedback after an interview simulation. It covers positive aspects, areas for improvement, and potential interviewer follow-ups, helping the candidate prepare for real interviews. ```markdown ### 🎀 If This Were a Real Interview: **What Went Well:** - [positive aspects] **What to Improve:** - [communication, approach, etc.] **Interviewer Would Likely:** - [Ask follow-up about...] - [Want to see optimization...] **Be Ready to Discuss:** - Why this approach? - Trade-offs? - How to handle [constraint]? ``` -------------------------------- ### Implement Sliding Window Algorithm in Python Source: https://context7.com/karanb192/algo-sensei/llms.txt A pseudocode skeleton for solving the Longest Substring Without Repeating Characters problem using a sliding window and hash set. ```python def lengthOfLongestSubstring(s): # Initialize: set for current chars, left pointer, result char_set = set() left = 0 max_length = 0 for right in range(len(s)): # While current char creates duplicate while s[right] in char_set: # Remove leftmost char, shrink window char_set.remove(s[left]) left += 1 # Add current char to set char_set.add(s[right]) # Update max length max_length = max(max_length, right - left + 1) return max_length ``` -------------------------------- ### Testing Strategy Templates Source: https://github.com/karanb192/algo-sensei/blob/main/templates/solutions/solution-template.md Boilerplate code for verifying solutions using assertions in various languages. ```python # Test 1: Basic case assert solution([example]) == expected # Test 2: Edge case assert solution([edge_case]) == expected ``` ```javascript // Test 1: Basic case console.assert(solution([example]) === expected); // Test 2: Edge case console.assert(solution([edgeCase]) === expected); ``` ```java // Test 1: Basic case assert solution(example).equals(expected); // Test 2: Edge case assert solution(edgeCase).equals(expected); ``` -------------------------------- ### Implement Sliding Window Pattern Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Use this template for problems requiring a dynamic window over an array. Ensure the window_invalid condition is correctly defined to shrink the window. ```python left = 0 for right in range(len(arr)): # Add arr[right] to window while window_invalid: # Remove arr[left] from window left += 1 # Update result ``` -------------------------------- ### Utilize Bisect for Binary Search Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Efficiently find insertion points or maintain sorted lists. ```python import bisect # Find insertion point pos = bisect.bisect_left(arr, x) # Leftmost pos = bisect.bisect_right(arr, x) # Rightmost # Insert in sorted order bisect.insort(arr, x) ``` -------------------------------- ### Implement Backtracking Pattern Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Use this recursive template for generating permutations or combinations. Ensure the base case correctly identifies a valid solution. ```python def backtrack(path, choices): if is_solution(path): result.append(path[:]) return for choice in choices: path.append(choice) backtrack(path, remaining_choices) path.pop() ``` -------------------------------- ### Implement Two Pointers Pattern Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Use this template for searching pairs or processing sorted arrays. Adjust the condition and pointer movement based on the specific problem requirements. ```python left, right = 0, len(arr) - 1 while left < right: if condition: # move appropriate pointer ``` -------------------------------- ### Apply Math Formulas Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Common mathematical expressions used in algorithmic complexity and problem solving. ```text n * (n + 1) / 2 ``` ```text n * (n + 1) * (2n + 1) / 6 ``` ```text C(n, k) = n! / (k! * (n-k)!) ``` ```text P(n, k) = n! / (n-k)! ``` ```text math.gcd(a, b) ``` ```text (a * b) / gcd(a, b) ``` -------------------------------- ### Binary Search Template Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md A standard implementation of binary search for finding a target in a sorted array. Ensure the input array is sorted before using this template. ```python left, right = 0, len(arr) - 1 while left <= right: mid = left + (right - left) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 ``` -------------------------------- ### Implement 3Sum with Two Pointers in Python Source: https://context7.com/karanb192/algo-sensei/llms.txt Solves the 3Sum problem by sorting the array and using a two-pointer approach to find unique triplets. Requires an input list of integers. ```python def threeSum(nums): nums.sort() # Enable two-pointer approach result = [] for i in range(len(nums) - 2): # Skip duplicates for first element if i > 0 and nums[i] == nums[i-1]: continue # Two pointers for remaining two elements left, right = i + 1, len(nums) - 1 target = -nums[i] while left < right: current_sum = nums[left] + nums[right] if current_sum == target: result.append([nums[i], nums[left], nums[right]]) # Skip duplicates while left < right and nums[left] == nums[left+1]: left += 1 while left < right and nums[right] == nums[right-1]: right -= 1 left += 1 right -= 1 elif current_sum < target: left += 1 else: right -= 1 return result # Example usage: print(threeSum([-1, 0, 1, 2, -1, -4])) # Output: [[-1, -1, 2], [-1, 0, 1]] ``` -------------------------------- ### Brute Force Solution Approach Source: https://context7.com/karanb192/algo-sensei/llms.txt A brute force approach to solving subarray problems with O(nΒ²) time complexity. ```python # O(nΒ²) - Check all subarrays def brute_force(arr, k): max_sum = float('-inf') for i in range(len(arr)): for j in range(i, len(arr)): max_sum = max(max_sum, sum(arr[i:j+1])) return max_sum ``` -------------------------------- ### Perform Bit Manipulation Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md Common bitwise operations for testing, setting, or clearing bits. ```text n & (1 << i) ``` ```text n | (1 << i) ``` ```text n & ~(1 << i) ``` ```text n ^ (1 << i) ``` ```text n & (n-1) == 0 ``` ```text bin(n).count('1') ``` -------------------------------- ### Depth-First Search (DFS) Recursion Template Source: https://github.com/karanb192/algo-sensei/blob/main/docs/dsa-cheatsheet.md A recursive implementation of Depth-First Search for traversing graphs or trees. Requires a `visited` set to prevent infinite loops in cyclic graphs. ```python def dfs(node, visited): if node in visited: return visited.add(node) for neighbor in graph[node]: dfs(neighbor, visited) ``` -------------------------------- ### Two Sum Optimal Solution using Hash Map Source: https://context7.com/karanb192/algo-sensei/llms.txt This is the optimal O(n) time complexity solution for the Two Sum problem using a hash map (dictionary in Python). It stores seen numbers and their indices, allowing for a single pass through the array. ```python def twoSum(nums, target): seen = {} # value -> index for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return [] ``` -------------------------------- ### Product of Array Except Self Problem Statement Source: https://context7.com/karanb192/algo-sensei/llms.txt This is the problem statement for 'Product of Array Except Self'. The goal is to return an array where each element is the product of all elements in the input array except for the element at the current index, without using division and in O(n) time. ```text **Product of Array Except Self** Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all elements of `nums` except `nums[i]`. You must solve it without using division and in O(n) time. Example: - Input: nums = [1, 2, 3, 4] - Output: [24, 12, 8, 6] ``` -------------------------------- ### Interview Closing Script Source: https://github.com/karanb192/algo-sensei/blob/main/modes/interview-mode.md Use this script to conclude the interview and invite the candidate to ask questions. ```text "Great work! Do you have any questions for me about the role or team?" [Answer questions in character] "Thanks for your time. We'll be in touch soon." ``` -------------------------------- ### Two Sum Brute Force Implementation Source: https://context7.com/karanb192/algo-sensei/llms.txt This is a brute-force approach to the Two Sum problem. It iterates through all possible pairs of numbers in the input array to find two that sum up to the target. Its time complexity is O(n^2). ```python def twoSum(nums, target): for i in range(len(nums)): for j in range(len(nums)): if i != j and nums[i] + nums[j] == target: return [i, j] return [] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.