DSA Learning Series - Contest 1

 Complexity Analysis + Basics Warm Up



1. Life, the Universe, and Everything

#include <iostream> using namespace std; int main() { int n; while(true) { cin>>n; if(n!=42) { cout<<n<<endl; } else { break; } } return 0; }

OR

ans = [] while(True): n = int(input()) if(n == 42): break else: ans.append(n) for i in ans: print(i)


2. Reverse The Number

#include <iostream> using namespace std; int main() { int t; cin >> t; while (t--) { int n, reverse = 0, rem; cin >> n; while (n != 0) { rem = n % 10; reverse = reverse * 10 + rem; n /= 10; } cout << reverse << endl; } return 0; }

3. Lapindromes

# cook your dish here for _ in range(int(input())): s = input() n=len(s) y = len(s)//2 l = [] l_ = [] l__ = [] for i in s: l.append(i) for i in range(y): l_.append(l[i]) l__.append(l[n-i-1]) l_.sort() l__.sort() if l_ == l__: print("YES") else: print("NO")

4. Smart Phone

#include <bits/stdc++.h> using namespace std; int main() { long long int a,b=0,n; cin>>n; vector<int> v(n); for (int i=0; i<n; i++){ cin>>v[i]; } sort(v.begin(), v.end()); for(int i=0; i<n; i++){ b = max(b,v[i]*(n-i)); } cout<<b<<endl; return 0; }


5. Carvans

for _ in range(int(input())): n = int(input()) l = [int(i) for i in input().split()] l_ = [] c=1 if n==1: print(1) else: l_ = l[0] for k in range(1,n): if l[k]<l_: l_ = l[k] c+=1 print(c)


6. Factorial


7. Coin Flip


8. Laddu


9. Multiple of 3



Video Explanation of 5 problems :