![]() |
Given a string “str” consisting of lowercase alphabets, the task is to find the minimum number of operations to be applied on string “str” such that all letters of the string “str” are the same. In one operation you can either remove all even indexed letters or you can remove all odd indexed characters. Examples:
Approach: The idea is to use the concept of recursion. Follow the steps below to solve the problem:
Below is the code implementation of the above approach: C++
Java
Python
C#
Javascript
Output
2 Time Complexity: O(N*log(N)), T(n) = 2*T(n/2) + 2O(n) now using master’s theorem time complexity comes out to be O(Nlog(N)). |
Reffered: https://www.geeksforgeeks.org
DSA |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |