Skip to content

Commit 8326dfd

Browse files
authored
Add files via upload
1 parent b250148 commit 8326dfd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

2024 January/Daily 03-01-24.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## 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)
2+
3+
4+
# Intuition
5+
<!-- Describe your first thoughts on how to solve this problem. -->
6+
Basic multiplication.
7+
# Approach
8+
<!-- Describe your approach to solving the problem. -->
9+
- I kept track of number of '1' in a row
10+
- Now iterated over every row of array
11+
- - counted the number of '1' in current row
12+
- - number of beams will the product of current number of device and previous number of devices
13+
- - added the product to answer
14+
- - now, the current one will become the previous one to next row
15+
---
16+
Have a look at the code , still have any confusion then please let me know in the comments
17+
Keep Solving.:)
18+
19+
# Complexity
20+
- Time complexity : $$O(l)$$
21+
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
22+
$$l$$ : length of array
23+
- Space complexity : $$O(1)$$
24+
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
25+
26+
# Code
27+
```
28+
class Solution {
29+
public int numberOfBeams(String[] bank) {
30+
int jawab = 0; // to store answer
31+
int picheek = 0; // to store number of '1' in previous state
32+
33+
for( String r : bank){
34+
int ek = (int) r.chars().filter( g -> g == '1').count(); // counting the number of '1' in current row
35+
if( ek != 0){ // number of beams will the product of current number of device and previous number of devices
36+
jawab += picheek*ek; // adding the product to answer
37+
picheek = ek; // now, the current one will become the previous one to next row
38+
}
39+
}
40+
return jawab;
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)