Skip to content

Instantly share code, notes, and snippets.

@HarshCasper
Last active May 13, 2020 05:41
Show Gist options
  • Save HarshCasper/5765deb8f5ec709e8b751db8af184d03 to your computer and use it in GitHub Desktop.
Save HarshCasper/5765deb8f5ec709e8b751db8af184d03 to your computer and use it in GitHub Desktop.
# https://www.codechef.com/LRNDSA01/problems/LAPIN
from math import ceil
n=int(input())
while n:
string=input()
length=len(string)
str1,str2=list(string[:length//2]),list(string[ceil(length/2):])
str1.sort()
str2.sort()
if str1==str2:
print("YES")
else:
print("NO")
n=n-1
// https://codeforces.com/problemset/problem/1141/B
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> numbers;
int num;
for(int i=0;i<n;i++){
cin>>num;
numbers.push_back(num);
}
for(int i=0;i<n;i++){
numbers.push_back(numbers[i]);
}
int temp=0,result=0;
for(int i=0;i<n*2;i++){
if(numbers[i]==1){
temp++;
}
else{
result=max(result,temp);
temp=0;
}
}
cout<<result;
return 0;
}
// https://www.codechef.com/LRNDSA01/problems/FLOW007
// https://www.geeksforgeeks.org/write-a-program-to-reverse-digits-of-a-number/
#include <iostream>
using namespace std;
int main() {
int k;
cin>>k;
while(k--){
long int n,rev=0,r;
cin>>n;
while(n>0){
r=n%10;
rev=rev*10+r;
n=n/10;
}
cout<<rev<<endl;
}
return 0;
}
// https://codeforces.com/problemset/problem/1234/B1
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int no;
Stack<Integer> phoneConversation=new Stack<Integer>();
for(int i=0;i<n;i++){
no=sc.nextInt();
if(!(phoneConversation.contains(no))){
if(phoneConversation.size() == k){
phoneConversation.remove(0);
phoneConversation.add(no);
} else {
phoneConversation.add(no);
}
}
else{
continue;
}
}
System.out.println(phoneConversation.size());
String ans="";
while(!(phoneConversation.isEmpty())){
ans=ans+phoneConversation.pop()+" ";
}
System.out.println(ans.trim());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment