Current streak:
0 days
Longest streak:
9 days
Less
More
#include <bits/stdc++.h>
bool patternMatches(string word, string pattern){
if(word.size() != pattern.size()) return false;
unordered_map<char,char> mpp;
unordered_set<char> usedChars;
for(int i=0; i<word.size(); i++){
if(mpp.find(word[i]) == mpp.end() && usedChars.find(pattern[i]) == usedChars.end()){
mpp[word[i]] = pattern[i];
usedChars.insert(pattern[i]);
}
else if(mpp[word[i]] != pattern[i]) return false;
}
return true;
}
vector<string> matchSpecificPattern(vector<string> words, int n, string pattern){
// Write your code here.
vector<string> ans;
for(int i=0; i<n; i++){
if(patternMatches(words[i], pattern)) ans.push_back(words[i]);
}
return ans;
}
#include <bits/stdc++.h>
vector<int> rotateMatRight(vector<vector<int>> mat, int n, int m, int k) {
// Write your code here.
k = k%m;
vector<int> ans;
for(int i=0; i<n; i++){
reverse(mat[i].begin(), mat[i].end());
reverse(mat[i].begin(), mat[i].begin()+k);
reverse(mat[i].begin()+k, mat[i].end());
for(int j=0; j<m; j++) ans.push_back(mat[i][j]);
}
return ans;
}
#include <bits/stdc++.h>
using namespace std;
string reverseStringWordWise(string input)
{
//Write your code here
reverse(input.begin(), input.end()); //reverse whole input sentence
int start=0;
while(start<input.size()){ //reverse each word
int end = start;
while(end<input.size() && input[end]!=' ') end++;
reverse(input.begin()+start, input.begin()+end);
start = end+1;
}
return input;
}
int main()
{
string s;
getline(cin, s);
string ans = reverseStringWordWise(s);
cout << ans << endl;
}
int findCelebrity(int n) {
// Write your code here.
int celebrity=0;
for(int i=1;i<n;i++){
if(knows(celebrity,i)) celebrity=i;
}
for(int i=0;i<n;i++){
if(i!=celebrity && (knows(celebrity,i)==1 || knows(i,celebrity)==0)){
return -1;
}
}
return celebrity;
}
vector<int> findStockSpans(vector<int>& prices) {
// Write your code here.
stack<int> s;
int n = prices.size();
vector<int> ans(n);
for(int i=0; i<n; i++){
while(!s.empty() && prices[i] > prices[s.top()]) s.pop();
ans[i] = s.empty() ? i+1 : i-s.top();
s.push(i);
}
return ans;
}
int calculateMinPatforms(int at[], int dt[], int n) {
// Write your code here.
sort(at, at+n);
sort(dt, dt+n);
int currPlatformsUsed = 1, maxPlatformsUsed = 1;
int i = 1, j = 0; // i points to next arrival, j points to departure
while(i<n && j<n){
if(at[i] <= dt[j]){
currPlatformsUsed++;
i++;
maxPlatformsUsed = max(maxPlatformsUsed,currPlatformsUsed);
}else{
currPlatformsUsed--;
j++;
}
}
return maxPlatformsUsed;
}
#include <bits/stdc++.h>
long long mod_exp(long long base, long long exp, long long mod) {
if (exp == 0) return 1;
if (exp&1==0) { //exp is odd
long long temp = mod_exp(base, exp / 2, mod);
return (temp * temp) % mod;
} else { //exp is even
return (base * mod_exp(base, exp - 1, mod)) % mod;
}
}
int powerOfPower(int A, int B, int C, int M)
{
// Write your code her
//Using Fermat's Little Theorem : a^(b^c)%m == a^(b^c % (m-1)) % m
//First we calculate B_pow_C=(b^c % (m-1))
//Then we calculate result=(a^B_pow_C) % m
long long B_pow_C = mod_exp(B, C, M - 1);
long long result = mod_exp(A, B_pow_C, M);
return result;
}
#include <bits/stdc++.h>
int findRowK(vector< vector< int> > &mat) {
// Write your code here
int n=mat.size();
bool flag;
for(int i=0;i<n;i++){
flag=true;
for(int j=0;j<n;j++){
if (i != j && (mat[i][j] == 1 || mat[j][i] == 0)) {
flag = false;
break;
}
}
if(flag==true) return i;
}
return -1;
}
#include <bits/stdc++.h>
bool isPossible(int *arr, int n)
{
// Write your code here.
if(n<=2) return true;
int count=0;
for(int i=1;i<n && count<=1 ;i++){
if (arr[i] < arr[i - 1]) {
count++;
if (i-2>=0 && arr[i-2]>arr[i]) arr[i] = arr[i-1];
else arr[i-1] = arr[i];
}
}
return count<=1;
}