Given a String of three Colours(G, B, Y) as input, the task is to print the resultant combined colour formed according to the rule given below:
// Rules for colour combination Blue(B) * Green(G) = Yellow(Y) Yellow(Y) * Blue(B) = Green(G) Green(G) * Yellow(Y) = Blue(B)
Input: str = "GBYGB" Output B Input: str = "BYB" Output Y
Approach: This problem can be solved as follows:
- Get the input string.
- Compare each alphabet with its adjacent characters.
- Use the above condition to determine the combination.
- print the output combination.
Below is the implementation of the above approach:
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.
- Count number of strings (made of R, G and B) using given combination
- Shortest possible combination of two strings
- Python | Print all string combination from given numbers
- Given a string, find its first non-repeating character
- Find the smallest window in a string containing all characters of another string
- Given a number, find the next smallest palindrome
- Find if a string is interleaved of two other strings | DP-33
- Find the first non-repeating character from a stream of characters
- Find Excel column name from a given column number
- Given a sorted dictionary of an alien language, find order of characters
- Find if an array of strings can be chained to form a circle | Set 1
- Given two strings, find if first string is a subsequence of second
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Find all distinct palindromic sub-strings of a given string
- Function to find Number of customers who could not get a computer
- Find the longest substring with k unique characters in a given string
- Find the maximum subarray XOR in a given array
- Find the most frequent digit without using array/string
- Find all strings formed from characters mapped to digits of a number
- How to find Lexicographically previous permutation?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.