@@ -5,6 +5,7 @@ This is my attempt to make the coding experience easier for you guys so that you
5
5
6
6
## Always here to assist you guys.
7
7
8
+ <<<<<<< HEAD
8
9
## Today's 04-01-24 [ Problem Link] ( https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty/description/ )
9
10
10
11
# Intuition
@@ -31,23 +32,44 @@ Use a HashMap (m) to store the frequency of each number in the array.
31
32
- - - - 3* n + 2 = 3* (n) + 2* (1) -> n+1 operations
32
33
- Return Result :
33
34
- - Return the total number of operations needed to make all numbers in the array divisible by 3.
35
+ =======
36
+ ## Today's 03-01-24 [ Problem Link] ( https://leetcode.com/problems/number-of-laser-beams-in-a-bank/description/?envType=daily-question&envId=2024-01-03 )
37
+
38
+ # Intuition
39
+ <!-- Describe your first thoughts on how to solve this problem. -->
40
+ Basic multiplication.
41
+ # Approach
42
+ <!-- Describe your approach to solving the problem. -->
43
+ - I kept track of number of '1' in a row
44
+ - Now iterated over every row of array
45
+ - - counted the number of '1' in current row
46
+ - - number of beams will the product of current number of device and previous number of devices
47
+ - - added the product to answer
48
+ - - now, the current one will become the previous one to next row
49
+ >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
34
50
---
35
51
Have a look at the code , still have any confusion then please let me know in the comments
36
52
Keep Solving.:)
37
53
38
54
# Complexity
39
55
- Time complexity : $$ O(l) $$
40
56
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
57
+ <<<<<<< HEAD
41
58
42
59
- Space complexity : $$ O(u) $$
43
60
44
61
$$ l $$ : size of array
45
62
$$ u $$ : number of unique letters in array
63
+ =======
64
+ $$ l $$ : length of array
65
+ - Space complexity : $$ O(1) $$
66
+ >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
46
67
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
47
68
48
69
# Code
49
70
```
50
71
class Solution {
72
+ <<<<<<< HEAD
51
73
public int minOperations(int[] nums) {
52
74
boolean haveone = false;
53
75
HashMap<Integer, Integer> m = new HashMap<>();
@@ -74,6 +96,20 @@ class Solution {
74
96
}
75
97
}
76
98
return operations;
99
+ =======
100
+ public int numberOfBeams(String[] bank) {
101
+ int jawab = 0; // to store answer
102
+ int picheek = 0; // to store number of '1' in previous state
103
+
104
+ for( String r : bank){
105
+ int ek = (int) r.chars().filter( g -> g == '1').count(); // counting the number of '1' in current row
106
+ if( ek != 0){ // number of beams will the product of current number of device and previous number of devices
107
+ jawab += picheek*ek; // adding the product to answer
108
+ picheek = ek; // now, the current one will become the previous one to next row
109
+ }
110
+ }
111
+ return jawab;
112
+ >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
77
113
}
78
114
}
79
115
```
0 commit comments