Given a large integer as a string str, the task is find the number of matchsticks required to represent it.
Input: str = “56”
5 sticks are required to represent 5 and
6 sticks are required to represent 6.
Input: str = “548712458645878”
Approach: Store the count of match sticks required to represent every digit from 0 to 9 in an array sticks. Now traverse the given string digit by digit and add the count of sticks required for the current digit.
Below is the implementation of the above approach:
Time Complexity: O(n)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sort the strings based on the numbers of matchsticks required to represent them
- Count of sticks required to represent the given string
- Minimum count of numbers required from given array to represent S
- Sort numbers based on count of letters required to represent them in words
- Minimum number of given powers of 2 required to represent a number
- Count of integers up to N which represent a Binary number
- Count of ways to represent N as sum of a prime number and twice of a square
- Count the number of operations required to reduce the given number
- Minimum count of numbers required ending with 7 to sum as a given number
- Count the number of carry operations required to add two numbers
- Count of minimum reductions required to get the required sum K
- Number of distinct ways to represent a number as sum of K unique primes
- 21 Matchsticks Problem
- Represent the given number as the sum of two composite numbers
- Represent a number as sum of minimum possible psuedobinary numbers
- Maximum number of distinct positive integers that can be used to represent N
- Count operations of the given type required to reduce N to 0
- Count of lines required to write the given String
- Minimum number of swaps required to make a number divisible by 60
- Minimum count of numbers required with unit digit X that sums up to N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.