I feel brute force for question 2 could have been done in a simpler way, reducing its space complexity ``` class Solution { public: bool swapCheck(int a,int b){ string x=to_string(a); string y=to_string(b); int count=0; for(int i=0;i
@@priyanshuthapliyal104 your second iteration, does not satisfy his initial state statment, where the multiplier is said to multiply all the elements atleast once
Actually the multiplication becomes circular after as soon as min*multiplier exceeds mx, not necessarily until each element is multiplied at least once! Eg=> assume multiplier = 2 0 [1, 2, 3] (initially array) 1 [2, 2, 3] 2 [4,2,3] 3 [4, 4, 3] 4 [4, 4, 6] 5 [8, 4, 6] 6 [8, 8, 6] 7 [8, 8, 12] ... notice after 1 where min in array is 2, 2*2 > 3 so we came out of the first loop . now see that [k=4] is 2*[k=1] and [k=7] is 2*[k =4] this will continue so the multiplication became circular from k=1 itself not from 4. hence the condition pq.top().first * multiplier
@@rajchinagundi7498 yes having the same doubt ,the pq will break prior before each place multiplied atleast 1, and if we write conditon pq.top().second
Sir, in the code from line 28-34 how are we ensuring that we are multiplying the element which has least index among all the similar numbers(if there are) ?
In B , we can simplify the process : CHECK THIS OUT class Solution { public: bool swapit(int i, int j, vector &nums) { string str1 = to_string(nums[i]); string str2 = to_string(nums[j]);
Please fill the Feedback form for PCD: forms.gle/tKfrRNnejeuZfUSt8
Best tutor at tle.
VERY GOOD EXPLANATION OF ALL THE FOUR PROBLEMS
bhai tu hi CF and CC contests ka videos bana...bahut acccha seekhatha hai :)
Thankyou bhai!
@@VirajChandra sch m esa lgta h ki kitna easy tha question jb smjhate ho bhaiya aap
good explanation viraj 👏👏
3 explanation was 🔥
Whew! I wounder how he made it to the observation.
I feel brute force for question 2 could have been done in a simpler way, reducing its space complexity
```
class Solution {
public:
bool swapCheck(int a,int b){
string x=to_string(a);
string y=to_string(b);
int count=0;
for(int i=0;i
Yes, this works!
Thanks @VraijChandra
good explanation of time complexity
How is the initial state achieved?
(1LL*multiplier*pq.top().first)%mod)
### **Initial Setup:**
- **Array:** `[2, 1, 3, 5, 6]`
- **k:** `5`
- **multiplier:** `4`
- **mod:** `1e9 + 7`
- **n:** `5` (size of the array)
### **Step 1: Calculate Maximum Element**
- **Maximum element (`maxi`):** `6`
### **Step 2: Build Initial Priority Queue**
We create a min-heap using a priority queue:
- After inserting all elements, the priority queue looks like this (based on the min-heap property):
```
pq: [(1, 1), (2, 0), (3, 2), (5, 3), (6, 4)]
```
### **Step 3: Process the Queue for `k` Operations**
We start multiplying the minimum element until the condition `(1LL * multiplier * pq.top().first) 6`
- The condition fails, so the loop terminates immediately. **`k` remains `4`** because the loop didn't perform any operation.
### **Step 4: Calculate Power**
- **Calculate Power:** `pow = modPower(4, k/n) = modPower(4, 4/5)`.
- **pow = modPower(4, 0) = 1** (integer division `4/5` gives `0`).
### **Step 5: Apply Remaining Multiplications**
The remainder of `k` (i.e., `k % n = 4 % 5 = 4`) means we multiply the next `4` elements by `4` directly.
- **Remaining `k = 4`, so we multiply the smallest `4` elements:**
- **1st Pop:**
- **Value:** `2` at index `0`.
- **Result:** `nums[0] = 2 * 4 = 8`
- **Priority Queue:**
```
pq: [(3, 2), (4, 1), (5, 3), (6, 4)]
```
- **2nd Pop:**
- **Value:** `3` at index `2`.
- **Result:** `nums[2] = 3 * 4 = 12`
- **Priority Queue:**
```
pq: [(4, 1), (6, 4), (5, 3)]
```
- **3rd Pop:**
- **Value:** `4` at index `1`.
- **Result:** `nums[1] = 4 * 4 = 16`
- **Priority Queue:**
```
pq: [(5, 3), (6, 4)]
```
- **4th Pop:**
- **Value:** `5` at index `3`.
- **Result:** `nums[3] = 5 * 4 = 20`
- **Priority Queue:**
```
pq: [(6, 4)]
```
### **Step 6: Final Array Construction**
Now, only one element (`6`) remains unmodified.
- **Final State of the Array:**
```
nums = [8, 16, 12, 20, 6]
```
### **Summary:**
- **Initial k:** `5`
- **k after the first loop:** `4`
- **Second iteration condition fails, so `k` remains `4`.**
The final array is `[8, 16, 12, 20, 6]`. The approach correctly handles the scenario where no further operations can be performed, ensuring that `k` is only reduced when an operation is actually executed.
@@priyanshuthapliyal104 your second iteration, does not satisfy his initial state statment, where the multiplier is said to multiply all the elements atleast once
@@rajchinagundi7498 Did you find out why is it working?
Actually the multiplication becomes circular after as soon as min*multiplier exceeds mx, not necessarily until each element is multiplied at least once! Eg=>
assume multiplier = 2
0 [1, 2, 3] (initially array)
1 [2, 2, 3]
2 [4,2,3]
3 [4, 4, 3]
4 [4, 4, 6]
5 [8, 4, 6]
6 [8, 8, 6]
7 [8, 8, 12]
...
notice after 1 where min in array is 2, 2*2 > 3 so we came out of the first loop .
now see that [k=4] is 2*[k=1]
and [k=7] is 2*[k =4]
this will continue
so the multiplication became circular from k=1 itself not from 4.
hence the condition pq.top().first * multiplier
@@rajchinagundi7498 yes having the same doubt ,the pq will break prior before each place multiplied atleast 1,
and if we write conditon pq.top().second
Sir, in the code from line 28-34 how are we ensuring that we are multiplying the element which has least index among all the similar numbers(if there are) ?
Since priority queue is made from a pair, second index is also maintained.
got 3rd problem very clearly
In B , we can simplify the process :
CHECK THIS OUT
class Solution {
public:
bool swapit(int i, int j, vector &nums) {
string str1 = to_string(nums[i]);
string str2 = to_string(nums[j]);
while(str1.size()>str2.size())
str2 = '0' + str2;
while(str1.size()