def getLargestString(s, k):
frequency_array = [0] * 26
for i in range(len(s)):
frequency_array[ord(s[i]) -
ord('a')] += 1
ans = ""
i = 25
while i >= 0:
if (frequency_array[i] > k):
temp = k
st = chr( i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
frequency_array[i] -= k
j = i - 1
while (frequency_array[j] <= 0 and
j >= 0):
j -= 1
if (frequency_array[j] > 0 and
j >= 0):
str1 = chr(j + ord( 'a'))
ans += str1
frequency_array[j] -= 1
else:
break
elif (frequency_array[i] > 0):
temp = frequency_array[i]
frequency_array[i] -= temp
st = chr(i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
else:
i -= 1
return ans
if name == "main":
S = input()
k = 3
print (getLargestString(S, k))
Python
Bob code
Telegram:- @allcoding1
frequency_array = [0] * 26
for i in range(len(s)):
frequency_array[ord(s[i]) -
ord('a')] += 1
ans = ""
i = 25
while i >= 0:
if (frequency_array[i] > k):
temp = k
st = chr( i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
frequency_array[i] -= k
j = i - 1
while (frequency_array[j] <= 0 and
j >= 0):
j -= 1
if (frequency_array[j] > 0 and
j >= 0):
str1 = chr(j + ord( 'a'))
ans += str1
frequency_array[j] -= 1
else:
break
elif (frequency_array[i] > 0):
temp = frequency_array[i]
frequency_array[i] -= temp
st = chr(i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
else:
i -= 1
return ans
if name == "main":
S = input()
k = 3
print (getLargestString(S, k))
Python
Bob code
Telegram:- @allcoding1
👍40
#include <bits/stdc++.h>
using namespace std;
int count(string s)
{
int N, i, cnt = 0, ans = 0;
N = s.length();
for (i = 0; i < N; i++) {
if (s[i] == 'R')
cnt++;
if (s[i] == 'L')
ans += cnt;
}
return ans;
}
int main()
{
string s = "RRLL";
cout << count(s) << endl;
return 0;
}
C++
Telegram - @allcoding1
using namespace std;
int count(string s)
{
int N, i, cnt = 0, ans = 0;
N = s.length();
for (i = 0; i < N; i++) {
if (s[i] == 'R')
cnt++;
if (s[i] == 'L')
ans += cnt;
}
return ans;
}
int main()
{
string s = "RRLL";
cout << count(s) << endl;
return 0;
}
C++
Telegram - @allcoding1
👍14❤1👎1
C++
Question:-
You are given Queries.each query consists of 3 integer X[i],Y[i] and N[i] where i donates the ith query The answer to ith query X[i],Y[i] and N[i] is denoted By (X[i],Y[i])^((X[i]+1),Y[i])^....^((X[i],N[i]*Y[i]) Find the sum of all answers modulo 10^9+7
Telegram:- @allcoding1
Question:-
You are given Queries.each query consists of 3 integer X[i],Y[i] and N[i] where i donates the ith query The answer to ith query X[i],Y[i] and N[i] is denoted By (X[i],Y[i])^((X[i]+1),Y[i])^....^((X[i],N[i]*Y[i]) Find the sum of all answers modulo 10^9+7
Telegram:- @allcoding1
👍14❤2
MAX = 10000
# prefix[i] is going to
# store count of primes
# till i (including i).
pt =[0]*(MAX + 1)
def abc():
prime = [1]*(MAX + 1)
p = 2
while(p * p <= MAX):
if (prime[p] == 1):
i = p * 2
while(i <= MAX):
prime[i] = 0
i += p
p+=1
for p in range(2,MAX+1):
pt[p] = pt[p - 1]
if (prime[p]==1):
pt[p]+=1
//@allcoding1
def query(a,b):
return pt[b]-pt[a-1]
n=int(input())
c=0
for i in range(n):
a,b=map(int,input().split())
abc()
c+=query(a,b)
mod=10**9+7
print(c%mod)
prime numbers in range[L,R]
All test cases passed
Telegram :- @allcoding1
# prefix[i] is going to
# store count of primes
# till i (including i).
pt =[0]*(MAX + 1)
def abc():
prime = [1]*(MAX + 1)
p = 2
while(p * p <= MAX):
if (prime[p] == 1):
i = p * 2
while(i <= MAX):
prime[i] = 0
i += p
p+=1
for p in range(2,MAX+1):
pt[p] = pt[p - 1]
if (prime[p]==1):
pt[p]+=1
//@allcoding1
def query(a,b):
return pt[b]-pt[a-1]
n=int(input())
c=0
for i in range(n):
a,b=map(int,input().split())
abc()
c+=query(a,b)
mod=10**9+7
print(c%mod)
prime numbers in range[L,R]
All test cases passed
Telegram :- @allcoding1
👍14😁4