revice easy array
Q
Approach-
note->- 1) we can use the outer loop for take the lenngth of indices
- 2) we use the [i][0] in first loop to increment the cols by making constant row
- 3)[i][1] use to change the row by making constant cols
- create two boolean array for row and col with row col size
- row[indices[i][0]] ^=true; same with col using [1]
- then count r and c values ; use following formulae;
Q
- first run loop till length
- after that take the sum from primary and secondary side
- if length is odd then we have to - the middle element because it comes twice
Q
- approch 1->while(0<nums[i]) - count++ nums[i]/=10;
- approch2-> Math.log10(nums[i])+1; it produce odd value for even and even for odd so we have to add 1 to it;
- approch3-> we set the limit like >9 && < =99 || like wise;
Q
- Use the new 2D ans for [col][row] because if matrix size is 2*4 the after transpose it becomes 4*2 thats why we give the row size depend on cols size.
- we use col =matrix[0].length because the size of col in first row is equal to all cols .
Q
solution
- In this problem first make a pointer on last index.
- add the k value to the last index like {1,2,0,0} + k=34,then 0+34=34%10 add this to list
- and make the k value to k=(num[i]+k)/10; to get 34/10= 3 is new k value.
- if k>0 means we have {9,9} in this case k=1 remains after all process so we have to add using k%10 and after k/10.
- Atlast reverse the list.
Q
- In this problem we use a for (i) to go each rows and for(j=logs[i][0] j<logs[i][1]) we have to skip the last year so we go till last year n-1.
- after the create one array and increment the index of each index by logs[j-1950]++.
- after this one check the max value and after find the first max we return with i+1950 year.
- Or we can make at logs[i][0]++ and logs[i][1]-- after that take the running sum apply same process.
Q
- we need array to store the two index.
- Two ways one we run for loop for i and use another for which is starting from next index.
- We can use hashmap to store the key with index as values.
Q
- We can approch this problem by two ways 1- by using Math.max directly or 2- using boolean value.
- first we have to check at each row so make one row for loop for all operation.
- Then first find the min in row and store the col value using that col value we can check at that col making row increment and decrement.
Q
- We have to take all the maximum sub array whose sum is greater.
- So we have to brute force take the sum of array of first index to till the end and check the max sum between the sum and max if sum<0? sum=0:continue.
- Best approach use the loop start from 1-> currentsum=max between(current+current value,current value)
- lastsum=max between currentsum, lastsum.
Q
- First we check the index is !=9 the simply increment the break, otherwise we have to place the 0 at that index and afterwards make the 0 index value to 1 by increasing the length by 1.
Q
- Easy just count the odd and event chips and find the minimum values between them to transfer from one position to another.
Q
- First we check the r*c and matrix row and col length if equals the return as it is or size equals the perform action if not then return .
- We have two approaches first one we can divide row->[i/col] and for col->[i%col] int this way we find the values.
- after atlast return it as it is storing it in new array.
Q
Q
- We have to make random array with the sum=0 of length n,So we create the array with length n and just place equal means +1 -1 +2 -2 like wise.
- important we increment the array by i+=2 beause we place the values already at the first and second index at one iteration.
Comments
Post a Comment