Find Servers That Handled Most Number of Requests, 1608. Design a Stack With Increment Operation, 1385. Leftmost Column with at Least a One, 1430. Minimum Swaps to Group All 1's Together, 1153. Remove Colored Pieces if Both Neighbors are the Same Color, 2039. Smallest String With A Given Numeric Value, 1665. Find the Longest Valid Obstacle Course at Each Position, 1966. Longest Subsequence Repeated k Times, 2015. Minimum Moves to Equal Array Elements II, 467. Keep Multiplying Found Values by Two, 2155. Minimum Possible Integer After at Most K Adjacent Swaps On Digits, 1509. What is the relational antonym of 'avatar'? Longest Even Odd Subarray With Threshold, 2763. Add Two Numbers 3. Check if There Is a Valid Parentheses String Path, 2271. Number of Times Binary String Is Prefix-Aligned, 1376. Rearrange Array to Maximize Prefix Score, 2588. Find the Subtasks That Did Not Execute, 1769. rev2023.7.17.43537. Number of Subarrays Having Even Product, 2496. Longest Binary Subsequence Less Than or Equal to K, 2313. Find the Index of the Large Integer, 1536. Customers Who Bought Products A and B but Not C, 1403. Construct the Lexicographically Largest Valid Sequence, 1719. LeetCode/Count number of substrings with exactly k distinct - GitHub Minimum Addition to Make Integer Beautiful, 2458. Apply Operations to Make All Array Elements Equal to Zero, 2776. Number of Submatrices That Sum to Target, 1080. Maximum Bags With Full Capacity of Rocks, 2280. Number of Smooth Descent Periods of a Stock, 2111. All Paths from Source Lead to Destination, 1061. Last Substring in Lexicographical Order, 1168. Count Number of Pairs With Absolute Difference K, 2007. Count the Number of Good Subsequences, 2541. Minimum Number of Arrows to Burst Balloons, 453. // C++ program to count number of substrings with // exactly k distinct characters in a given string # include < bits/stdc++.h > using namespace std; Groups of Special-Equivalent Strings, 915. Check if There is a Valid Path in a Grid, 1398. Starting the Prompt Design Site: A New Home in our Stack Exchange Neighborhood. Minimum Recolors to Get K Consecutive Black Blocks, 2380. Find the City With the Smallest Number of Neighbors at a Threshold Distance, 1335. Create Target Array in the Given Order, 1391. Find Nearest Point That Has the Same X or Y Coordinate, 1780. Tiling a Rectangle with the Fewest Squares, 1247. Can You Eat Your Favorite Candy on Your Favorite Day? NOTE for people who are wondering how it could be possible to build a tree that contains O(N^2) characters in O(N) time: There's a trick to the representation of a suffix tree. Longest ZigZag Path in a Binary Tree, 1374. Count the Number of Square-Free Subsets, 2575. Minimum Number of Work Sessions to Finish the Tasks, 1989. Sort the Students by Their Kth Score, 2546. Maximum Difference Between Increasing Elements, 2018. Path In Zigzag Labelled Binary Tree, 1111. Largest Number After Digit Swaps by Parity, 2232. Friend Requests II: Who Has the Most Friends, 615. Lowest Common Ancestor of a Binary Tree, 255. Evaluate the Bracket Pairs of a String, 1812. Difference Between Ones and Zeros in Row and Column, 2486. Count of distinct substrings of a string using Suffix Trie Minimum Operations to Make a Subsequence, 1714. Substrings That Begin and End With the Same Letter, 2084. Minimum Increment to Make Array Unique, 947. Maximum Profit of Operating a Centennial Wheel, 1601. The distinct substrings are a, ab, aba, abab, ababa, b, ba, bab, baba. Amount of New Area Painted Each Day, 2160. Evaluate the Bracket Pairs of a String, 1812. User Activity for the Past 30 Days I, 1142. Find the City With the Smallest Number of Neighbors at a Threshold Distance, 1335. Find Substring With Given Hash Value, 2158. Count Pairs of Equal Substrings With Minimum Difference, 1798. Maximum Sum of Distinct Subarrays With Length K, 2470. Customer Who Visited but Did Not Make Any Transactions, 1582. String Transforms Into Another String, 1155. What is the state of the art of splitting a binary file by size? Users With Two Purchases Within Seven Days, 2230. Minimum Fuel Cost to Report to the Capital, 2479. Number of Good Ways to Split a String, 1526. Minimum Number of Days to Make m Bouquets, 1485. Numbers With Same Consecutive Differences, 971. 1746. Intersection of Three Sorted Arrays, 1217. Length of the Longest Valid Substring. Replace Elements with Greatest Element on Right Side, 1300. Minimum Adjacent Swaps to Reach the Kth Smallest Number, 1851. 238 Companies Let's define a function countUniqueChars (s) that returns the number of unique characters on s. For example, calling countUniqueChars (s) if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since they appear only once in s, therefore countUniqueChars (s) = 5. Count Equal and Divisible Pairs in an Array, 2177. 2549. Count Distinct Numbers on Board - LeetCode Solutions Customers with Maximum Number of Transactions on Consecutive Days, 2753. Number of Ways to Arrive at Destination, 1978. Minimum Number of Swaps to Make the String Balanced, 1964. Employees Whose Manager Left the Company, 1979. Minimum Degree of a Connected Trio in a Graph, 1764. Minimum Subsequence in Non-Increasing Order, 1404. Count Unreachable Pairs of Nodes in an Undirected Graph, 2320. Lexicographically Smallest String After Applying Operations, 1628. Lexicographically Smallest Beautiful String, 2669. @MattTimmermans Say for example, my original string. Maximum Element After Decreasing and Rearranging, 1848. Execute Asynchronous Functions in Parallel, 2730. Minimum Operations to Make Array Equal, 1553. Maximum White Tiles Covered by a Carpet, 2273. Friend Requests II: Who Has the Most Friends, 615. Below is implementation based on above idea. (Ep. Greatest English Letter in Upper and Lower Case, 2311. Number of Subarrays With GCD Equal to K, 2449. Find Total Time Spent by Each Employee, 1743. LeetCode-Solutions/number-of-distinct-substrings-in-a-string.cpp at Best Time to Buy and Sell Stock with Transaction Fee, 730. Maximum of Minimum Values in All Subarrays, 1951. it can be written as a + a where a is some string). Maximum Number of Integers to Choose From a Range II, 2566. Maximum Distance Between a Pair of Values, 1857. First Day Where You Have Been in All the Rooms, 1999. Successful Pairs of Spells and Potions, 2302. Check If Word Is Valid After Substitutions, 1005. Maximum Score After Splitting a String, 1423. Largest Number After Mutating Substring, 1950. Equal Sum Arrays With Minimum Number of Operations, 1779. Minimum Consecutive Cards to Pick Up, 2263. Maximum Absolute Sum of Any Subarray, 1750. Max Sum of a Pair With Equal Sum of Digits, 2344. The Most Frequently Ordered Products for Each Customer, 1597. Check If a String Contains All Binary Codes of Size K, 1464. Connect and share knowledge within a single location that is structured and easy to search. Count Nodes Equal to Sum of Descendants, 1974. Queries on Number of Points Inside a Circle, 1830. Minimum Swaps To Make Sequences Increasing, 828. Minimum Number of Operations to Make All Array Elements Equal to 1, 2656. Number of Subarrays Having Even Product, 2496. Count Positions on Street With Required Brightness, 2238. Maximum Score From Removing Substrings, 1718. Find the Student that Will Replace the Chalk, 1896. Largest 3-Same-Digit Number in String, 2265. Count the Digits That Divide a Number, 2521. Unique Substrings in Wraparound String, 497. Average Value of Even Numbers That Are Divisible by Three, 2457. Minimum Possible Integer After at Most K Adjacent Swaps On Digits, 1509. Append Characters to String to Make Subsequence, 2489. I know a O(n^2) approach is possible, but is there a more efficient algorithm? Number of Ways to Divide a Long Corridor, 2148. https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/. Minimum Length of String After Deleting Similar Ends, 1751. Sort Array by Moving Items to Empty Space, 2461. Number of Subarrays with Bounded Maximum, 798. Construct Binary Tree from Preorder and Inorder Traversal, 106. Number of Subarrays With LCM Equal to K, 2471. Coordinate With Maximum Network Quality, 1621. Make the XOR of All Segments Equal to Zero, 1789. Closest Nodes Queries in a Binary Search Tree, 2477. This code is a guessing game in Python which uses a While Loop with 3 guesses, Excel Needs Key For Microsoft 365 Family Subscription. Maximum Number of Events That Can Be Attended II, 1752. Determine Whether Matrix Can Be Obtained By Rotation, 1887. Lowest Common Ancestor of a Binary Tree II, 1647. Flatten Nested List Iterator. Minimum Number of Work Sessions to Finish the Tasks, 1989. Maximum Side Length of a Square with Sum Less than or Equal to Threshold, 1293. Kids With the Greatest Number of Candies, 1432. Smallest K-Length Subsequence With Occurrences of a Letter, 2031. Final Prices With a Special Discount in a Shop, 1477. Smallest Value After Replacing With Sum of Prime Factors, 2508. Minimum Cost to Reach City With Discounts, 2095. Determine if String Halves Are Alike, 1707. Average Salary Excluding the Minimum and Maximum Salary, 1493. Minimum Interval to Include Each Query, 1855. Check Whether Two Strings are Almost Equivalent, 2071. Maximum Score Words Formed by Letters, 1261. All Elements in Two Binary Search Trees, 1308. Eliminate Maximum Number of Monsters, 1928. Build an Array With Stack Operations, 1442. Kth Smallest Element in a Sorted Matrix, 381. Unique Length-3 Palindromic Subsequences, 1931. Kth Smallest Number in Multiplication Table, 671. Concatenation of Consecutive Binary Numbers, 1684. Height of Binary Tree After Subtree Removal Queries, 2459. Find Words That Can Be Formed by Characters, 1163. Find the Divisibility Array of a String, 2576. Minimum Score Triangulation of Polygon, 1047. Number of Unique Flavors After Sharing K Candies, 2108. Find Maximum Number of String Pairs, 2749. Number of Subarrays with Bounded Maximum, 798. String Transforms Into Another String, 1155. Minimum Value to Get Positive Step by Step Sum, 1414. Maximum Sum With Exactly K Elements, 2657. Longest Substring with At Least K Repeating Characters, 421. All Valid Triplets That Can Represent a Country, 1624. Check Whether Two Strings are Almost Equivalent, 2071. "abcca": Count of distinct characters = 3. Remove Duplicates from Sorted List II, 103. 0341. Minimum White Tiles After Covering With Carpets, 2210. Capacity To Ship Packages Within D Days, 1013. Removing Minimum and Maximum From Array, 2093. Find the Start and End Number of Continuous Ranges, 1287. Number of Students Unable to Eat Lunch, 1703. Second Minimum Time to Reach Destination, 2046. Next Greater Numerically Balanced Number, 2051. Minimum Operations to Convert Number, 2060. Maximum Number of Robots Within Budget, 2399. Reverse Subarray To Maximize Array Value, 1333. Input Format A string Output Format A number representing count of substrings with exactly K unique characters. Count Substrings with Only One Distinct Letter - LeetCode Can you solve this real interview question? Minimum Operations to Make Array Equal II, 2545. Unique Substrings in Wraparound String, 497. Find All K-Distant Indices in an Array, 2201. Design an Expression Tree With Evaluate Function, 1633. Longest Subarray With Maximum Bitwise AND, 2422. User Activity for the Past 30 Days II, 1144. Number of Smooth Descent Periods of a Stock, 2111. Maximum Product Difference Between Two Pairs, 1916. Count the Number of Good Subsequences, 2541. Maximum Number of Vowels in a Substring of Given Length, 1457. Remove Duplicates From an Unsorted Linked List, 1838. Maximum Number of People That Can Be Caught in Tag, 1996. Amount of Time for Binary Tree to Be Infected, 2388.