Given two integer N and K, the task is to find an array of size K containing only even or odd elements where the sum of all the elements of the array is N. If there is no such array print “No”.
Input: N = 18, K = 3
Output: 6 6 6
Input: N = 19, K = 5
Output: 3 3 3 3 7
Approach: The idea is to choose the smallest even or odd number K-1 times and Finally, compute the last number with the help of total sum. If the last number is also even for the even number and odd for the smallest odd number. Then it is possible to choose such an array. Otherwise, there is no such array possible.
Below is the implementation of the above approach:
2 2 6
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.
- Represent N as sum of K odd numbers with repetitions allowed
- Represent K^N as the sum of exactly N numbers
- Represent N as sum of K even numbers
- Represent K as sum of N-bonacci numbers
- Represent the given number as the sum of two composite numbers
- Represent a number as sum of minimum possible psuedobinary numbers
- Represent the fraction of two numbers in the string format
- Minimum count of numbers required from given array to represent S
- Sort the strings based on the numbers of matchsticks required to represent them
- Sort numbers based on count of letters required to represent them in words
- Pick maximum sum M elements such that contiguous repetitions do not exceed K
- Represent n as the sum of exactly k powers of two | Set 2
- Represent a given set of points by the best possible straight line
- Count of integers up to N which represent a Binary number
- Check given array of size n can represent BST of n levels or not
- Represent (2 / N) as the sum of three distinct positive integers of the form (1 / m)
- Count of matchsticks required to represent the given number
- Count of sticks required to represent the given string
- Different types of Coding Schemes to represent data
- Maximum number of distinct positive integers that can be used to represent 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.