Skip to content

Commit cee82be

Browse files
committed
.
2 parents 17fcd02 + 8326dfd commit cee82be

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

2024 January/Daily 03-01-24.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,48 @@ class Solution {
4040
return jawab;
4141
}
4242
}
43+
=======
44+
## 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)
45+
46+
47+
# Intuition
48+
<!-- Describe your first thoughts on how to solve this problem. -->
49+
Basic multiplication.
50+
# Approach
51+
<!-- Describe your approach to solving the problem. -->
52+
- I kept track of number of '1' in a row
53+
- Now iterated over every row of array
54+
- - counted the number of '1' in current row
55+
- - number of beams will the product of current number of device and previous number of devices
56+
- - added the product to answer
57+
- - now, the current one will become the previous one to next row
58+
---
59+
Have a look at the code , still have any confusion then please let me know in the comments
60+
Keep Solving.:)
61+
62+
# Complexity
63+
- Time complexity : $$O(l)$$
64+
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
65+
$$l$$ : length of array
66+
- Space complexity : $$O(1)$$
67+
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
68+
69+
# Code
70+
```
71+
class Solution {
72+
public int numberOfBeams(String[] bank) {
73+
int jawab = 0; // to store answer
74+
int picheek = 0; // to store number of '1' in previous state
75+
76+
for( String r : bank){
77+
int ek = (int) r.chars().filter( g -> g == '1').count(); // counting the number of '1' in current row
78+
if( ek != 0){ // number of beams will the product of current number of device and previous number of devices
79+
jawab += picheek*ek; // adding the product to answer
80+
picheek = ek; // now, the current one will become the previous one to next row
81+
}
82+
}
83+
return jawab;
84+
}
85+
}
86+
>>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
4387
```

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This is my attempt to make the coding experience easier for you guys so that you
55

66
## Always here to assist you guys.
77

8+
<<<<<<< HEAD
89
## Today's 04-01-24 [Problem Link](https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty/description/)
910

1011
# Intuition
@@ -31,23 +32,44 @@ Use a HashMap (m) to store the frequency of each number in the array.
3132
- - - - 3*n + 2 = 3*(n) + 2*(1) -> n+1 operations
3233
- Return Result :
3334
- - 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
3450
---
3551
Have a look at the code , still have any confusion then please let me know in the comments
3652
Keep Solving.:)
3753

3854
# Complexity
3955
- Time complexity : $$O(l)$$
4056
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
57+
<<<<<<< HEAD
4158

4259
- Space complexity : $$O(u)$$
4360

4461
$$l$$ : size of array
4562
$$u$$ : number of unique letters in array
63+
=======
64+
$$l$$ : length of array
65+
- Space complexity : $$O(1)$$
66+
>>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
4667
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
4768
4869
# Code
4970
```
5071
class Solution {
72+
<<<<<<< HEAD
5173
public int minOperations(int[] nums) {
5274
boolean haveone = false;
5375
HashMap<Integer, Integer> m = new HashMap<>();
@@ -74,6 +96,20 @@ class Solution {
7496
}
7597
}
7698
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
77113
}
78114
}
79115
```

0 commit comments

Comments
 (0)