 # JOEYBIR - Editorial

Practice

Author: Ayush Shukla
Tester: Sparsh Kedia
Editorialist: Sakchi Agarwal

SIMPLE

Basic Maths

# PROBLEM:

You have to find the maximum area of closed loop which you can form by traveling

# EXPLANATION:

If the string of steps forms a closed loop then number of left and right steps will be same and up and down steps will be same i.e (L = R) and (U = D). The maximum area that can be covered will be (L*R) because this is the maximum leftmost and topmost point we can reach.
If we choose any other combination of these steps, we cannot reach the leftmost and the topmost point possible.

# SOLUTIONS:

Setter's Solution
``````#include <bits/stdc++.h>
using namespace std;

main(){
int t;
cin >> t;
while(t--){
string s;
cin>>s;
int len = s.length();
int left=0,down=0;
for(int i=0;i<len;i++){
if(s[i]=='l'){
left++;
}
else if(s[i]=='d'){
down++;
}

}
cout<<left*down<<"\n";
}
}
``````
Tester's Solution
``````import math
t = int(input())
while t>0 :
s = input()
l = len(s)
cnt1 = 0
cnt2 = 0
for i in range(0,l):
if(s[i]=="l"):
cnt1+=1
if(s[i]=="d"):
cnt2+=1
print(cnt1*cnt2)
t = t-1
``````

Feel free to share your approach.
Happy Coding !

1 Like