for making all possible variation of string we can use concept of generate permutation with a baseCase of -> if(swapCnt>=2 || index>=nums.size()){ store string } then it would work same but we have clear code.
Sir, dont make us understood on code , try to explain on the smart board,dry run and all it wiil be very helpful for us ,i like this channel i will subscribe it
My question is for the 4th one. for every digit we are checking after 0th, 1st, 2nd swap they are previously present in the map or not and before that we are storing them in set(all unique ones). But here we are checking 0th swap on i with 0th,1st , 2nd swap on j element with the help of map. But what about 1st swap on i with 0th,1st,2nd(not 2nd because we are swaping ith element one time) swap on j....and like that 1|0 combination and 2|0 combination and 1|1 combination. I hope my questions are clear to you. How are you considering those conditions
Can anyone tell why it is giving WA - class Solution { public: using ll = long long; int MOD = 1e9 + 7; ll findexp(ll base, ll exponent) { ll result = 1; while (exponent > 0) { if (exponent % 2 == 1) { result = (result * base) % MOD; } base = (base * base) % MOD; exponent /= 2; } return result; } vector getFinalState(vector& nums, int k, int x) { if(x==1) return nums; int n = nums.size(); int maxi = *max_element(nums.begin(), nums.end()); priority_queue pq; for (int i = 0; i < n; i++) { pq.push({nums[i], i}); } while (k && pq.top().first * x
class Solution { public: long long powermod(long long x, long long y, long long p){ long long res = 1; if (x == 0){return 0;} while (y > 0){ if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } void print (priority_queue heap){ for (int i=0;i
bhai 3rd question itna dhaansu smjhaya, maza aa gya
thank you for the amazing explanation
for making all possible variation of string we can use concept of generate permutation with a baseCase of -> if(swapCnt>=2 || index>=nums.size()){ store string } then it would work same but we have clear code.
Sir, dont make us understood on code , try to explain on the smart board,dry run and all it wiil be very helpful for us ,i like this channel i will subscribe it
S sir please
(3&4) both are easy after seeing your video sir, I don't know why i am not thing of that...😢😢
Great explanation of Q3. Watched many videos, but was unable to understand. Finally understood from ur video.
My question is for the 4th one. for every digit we are checking after 0th, 1st, 2nd swap they are previously present in the map or not and before that we are storing them in set(all unique ones). But here we are checking 0th swap on i with 0th,1st , 2nd swap on j element with the help of map. But what about 1st swap on i with 0th,1st,2nd(not 2nd because we are swaping ith element one time) swap on j....and like that 1|0 combination and 2|0 combination and 1|1 combination. I hope my questions are clear to you. How are you considering those conditions
very good explanation bro,specially 3rd question
Amazing explanation
excellent explanation with quality code
amazing explantion 🙂
Understood
Nice explanation abhinav
3rd qs badiya samjhaya bro
in first while loop in 3rd question you are not poping the top element why this will not give tle??
Great code, Man
Can anyone tell why it is giving WA -
class Solution {
public:
using ll = long long;
int MOD = 1e9 + 7;
ll findexp(ll base, ll exponent) {
ll result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) {
result = (result * base) % MOD;
}
base = (base * base) % MOD;
exponent /= 2;
}
return result;
}
vector getFinalState(vector& nums, int k, int x) {
if(x==1) return nums;
int n = nums.size();
int maxi = *max_element(nums.begin(), nums.end());
priority_queue pq;
for (int i = 0; i < n; i++) {
pq.push({nums[i], i});
}
while (k && pq.top().first * x
class Solution {
public:
void solve(string st,unordered_map&mp,unordered_set&s,int count)
{
if(count==2)return;
for(int i = 0; i < st.size(); i++){
for(int j = i+1; j < st.size(); j++){
swap(st[j],st[i]);
int number = stoi(st);
if(s.find(number)==s.end())
{
mp[number]++;
s.insert(number);
}
solve(st,mp,s,count+1);
swap(st[j],st[i]);
}
}
}
int countPairs(vector& nums) {
unordered_mapmp;
int count = 0;
sort(nums.begin(),nums.end());
reverse(nums.begin(),nums.end());
for(auto it : nums){
count+=mp[it];
string st = to_string(it);
mp[it]++;
unordered_sets;
s.insert(it);
solve(st,mp,s,0);
}
return count;
}
};
amazing
class Solution {
public:
long long powermod(long long x, long long y, long long p){
long long res = 1;
if (x == 0){return 0;}
while (y > 0){
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void print (priority_queue heap){
for (int i=0;i
same bro failing somewhere in 500th tetst case
Nice 😊
Last question ka solution aisa lga jaise tle eliminator se copy paste kr diya ho 😂. But loved it
gg, but please try to keep the handwriting more legible. had a hardtime reading some of the digits in q3 solution.
Hey can any one tell why this case only passed 570 test cases, q2
class Solution {
public:
int length(int num){
if(num == 0) return 1;
int len = 0;
while(num){
len++;
num /= 10;
}
return len;
}
int reverseDigits(int num)
{
int rev_num = 0;
while (num > 0) {
rev_num = rev_num * 10 + num % 10;
num = num / 10;
}
return rev_num;
}
bool check (int num1, int num2){
if(num1 == num2) return true;
int temp1 = num1, temp2 = num2;
int cnt = 0;
if(length(num1) 0){
int a = temp1 % 10;
int b = temp2 % 10;
if(a != b) cnt++;
temp1 /= 10;
temp2 /= 10;
}
while (temp1 > 0 || temp2 > 0) {
cnt++;
temp1 /= 10;
temp2 /= 10;
}
if(cnt != 2) return false;
return true;
}
int countPairs(vector& nums) {
int cnt = 0;
for(int i = 0;i
Nice
Waiting for 4 hours when we gonna upload videos and I can upsolve the remaining ones. 😅😅
why brute force in q2 works can anyone give explanation?
Constraints are low
Bhai Mera only 560 test cases pass hua pq min heap lagaya tha
don't stop !
i guess if you can explain in Hindi only then your explanation will be better then what it is now