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)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Find maximum number that can be formed using digits of a given number
- Count pairs from 1 to N such that their Sum is divisible by their XOR
- Count of pairs in a given range with sum of their product and sum equal to their concatenated number
- Possible values of Q such that, for any value of R, their product is equal to X times their sum
- Program to find if two numbers and their AM and HM are present in an array using STL
- Count of Substrings that can be formed without using the given list of Characters
- Check whether a straight line can be formed using N co-ordinate points
- Largest square which can be formed using given rectangular blocks
- Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Find the largest number that can be formed by changing at most K digits
- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Count different numbers possible using all the digits their frequency times
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find K numbers with sum equal to N and sum of their squares maximized
- Find two numbers made up of a given digit such that their difference is divisible by N
- Find two numbers such that difference of their squares equal to N
- Find two distinct numbers such that their LCM lies in given range
- Count numbers which can be constructed using two numbers
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.