@@ -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---
3551Have a look at the code , still have any confusion then please let me know in the comments
3652Keep 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```
5071class 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