P

@praveen11

sort 0's,1's,2's

Python
4 years ago
n=int(input()) l=[int(i) for i in input().split()] zeroes=l.count(0) ones=l.count(1) twos=l.count(2) print("count of 0's,1's,2's :") print(zeroes,ones,twos) while(zeroes!=0): print("0",end=" ") zeroes=zeroes-1

Palindromic string

Python
4 years ago
t=int(input()) for i in range(t): s=input() x="" for j in s: if(j>="a" and j<="z"): x=x+chr(ord(j)-32) elif(j>="A" and j<="Z"): x=x+j if(x==x[::-1]):

valid mountain

C++
4 years ago
#include<iostream> #include<cmath> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; }

check(left array sum = right array sum)

C++
4 years ago
#include<iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; int a[n],left=0,right=0; for(int i=0;i<n;i++){

Array Subset of an other Array

Python
4 years ago
l1=[int(i) for i in input().split()] l2=[int(i) for i in input().split()] s1=set(l1) p=len(s1) s2=s1.union(set(l2)) if(p==len(s2)): print("Yes") else: print("No")

longest consecutive sequence

C++
4 years ago
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ vector<long long int> v; long long int input; while(cin>>input){ v.push_back(input); }

subarray with given sum

C++
4 years ago
#include<iostream> using namespace std; int subarraysum(long long int a[],int n,long long int sum){ long long int curr_sum=a[0]; int start=0; for(int i=1;i<=n;i++){ while(curr_sum>sum && start<i-1){ curr_sum=curr_sum-

right rotation of an array

C++
4 years ago
#include<iostream> using namespace std; void reverse(int a[],int low,int high){ while(low<high){ int temp=a[low]; a[low]=a[high]; a[high]=temp; low++; high--; }

Excursion:- data-structures-and-algorithms-coding-contest-November

C++
4 years ago
#include<iostream> using namespace std; int rooms(int x,int k){ if(x%k==0){ return x/k; } else{ return (x/k)+1; } }

Largest Sum Contiguous Subarray (Kadane’s Algorithm)

C++
4 years ago
#include <iostream> #include<climits> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; }

print the string with max length in a given list of strings in given string

Python
4 years ago
l=["abc","apple"] s="abcpple" max=-1 res="" curr_str="" for i in l: k=0 for j in i: if(j in s[k:]): k=s.index(j)

removing nums,special chars,spaces from given string

Python
4 years ago
t=int(input()) for j in range(t): s=input() ans="" for i in s: if(i>="a" and i<="z"): ans=ans+chr(ord(i)-32) elif(i>="A" and i<="Z"): ans=ans+i print(ans)

Inverted Hollow Pyramid Star Pattern

Python
4 years ago
n = int(input()) for i in range(1, n+1): for j in range(0, i): print(" ", end="") for j in range(1, (n*2 - (2*i - 1))+1): if i == 1 or j == 1 or j ==(n*2 -(2*i-1)): print("*", end="") else:

count number of primes in subsets of given string

Python
4 years ago
def countprimes(l): count=0 for i in l: flag=0 if(i>1): for j in range(2,(i//2)+1): if(i%j==0): flag=1 break if(flag==0):

problem on dictionary

Python
4 years ago
n=int(input()) l=[] for i in range(n): l.append(input()) print(l) d={} for i in l: d[i]=True print(d) t=int(input())

taking user input of list if elements are given line by line using exception

Python
4 years ago
#l=[int(i) for i in input().split()] try: l=[] while True: l.append(int(input())) except: print(l)

print numbers from the given string

Python
4 years ago
s=input() l=[] num="" for i in s: if(i>='0' and i<='9'): num=num+i else: if(num!=""): l.append(num) num=""

Winner of an election GFG practice problem

C++
4 years ago
/* Given an array of names of candidates in an election. A candidate name in array represents a vote casted to the candidate. The task is to print the name of candidates received maximum vote. If there is tie, print lexicographically smaller name

remove the following keys from dictionary

Python
4 years ago
sampleDict = { "name": "Kelly", "age":25, "salary": 8000, "city": "New york" } keysToRemove = ["name", "salary"] sampleDict={k: sampleDict[k] for k in sampleDict.keys() - keysToRemove} print(sampleDict)

Create a new dictionary by extracting the following keys from a below dictionary

Python
4 years ago
sampleDict = { "name": "Kelly", "age":25, "salary": 8000, "city": "New york" } keys=['name','age'] d={x:sampleDict[x] for x in keys} print(d)