Valence number of an atom is defined as the exact number of bonds the atom must form with other atoms. Given valence number of 3 atoms, the task is to determine if they can form a molecule together or not. Atoms can form multiple bonds with each other.
Input: 2 4 2 Output: YES The bonds are between the following atoms: 1 - 2 1 - 2 2 - 3 2 - 3 Input: 1 2 3 Output: NO
Approach: Let the valence numbers be a, b and c. Let c be the largest. We have 2 cases in which the molecule cannot be formed:
- a+b+c is odd: Since every bond decreases the valence number of 2 atoms by 1, the sum of valence numbers should be an even number.
- a+b < c: In this case, c will be left unsatisfied even if every bond is formed with it.
Below is the implementation of the above approach:
Time complexity: O(1)
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.
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Find Kth number from sorted array formed by multiplying any two numbers in the array
- Maximum factors formed by two numbers
- Sum of sum of all subsets of a set formed by first N natural numbers
- Sum of all subsets of a set formed by first n natural numbers
- GCD of two numbers formed by n repeating x and y times
- Count numbers formed by given two digit with sum having given digits
- Count of decreasing pairs formed from numbers 1 to N
- N digit numbers divisible by 5 formed from the M digits
- Product of all Subsets of a set formed by first N natural numbers
- Minimum sum of two numbers formed from digits of an array
- Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9
- Sum of series formed by difference between product and sum of N natural numbers
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Check if number formed by joining two Numbers is Perfect Cube
- Find the largest number that can be formed by changing at most K digits
- Find Nth even length palindromic number formed using digits X and Y
- Find position of given term in a series formed with only digits 4 and 7 allowed
- Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
- Find the Largest Cube formed by Deleting minimum Digits from a number
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.