Python Program to find the Larger String without Using Built-in Functions
Given two strings. The task is to find the larger string without using built-in functions.
Input: GeeksforGeeks Geeks Output: GeeksforGeeks Input: GeeksForFeeks is an good Computer Coding Website It offers several topics Output: GeeksForFeeks is an good Computer Coding Website
- Take two strings in separate variables.
- Initialize the two count variables to zero.
- Use a for loop to traverse through the characters in the string and increment the count variables each time a character is encountered.
- Compare the count variables of both the strings.
- Print the larger string.
Below is the complete program based on the above approach:
Larger string is: GeeksForFeeks is an good Computer Coding Website
Time Complexity: O(n)
Auxiliary Space: O(1)
Program Explanation :
- User must enter two strings and store it in separate variables.
- The count variables are initialized to zero.
- The for loop is used to traverse through the characters in the strings.
- The count variables are incremented each time a character is encountered.
- The count variables are then compared and the larger string is printed.