Skip to content

15-Ab/Leetcode-Daily-Challenge

Repository files navigation

Leetcode Daily Challenge Solutions

This is my attemp to make the coding experience easier for you guys so that you can easily learn what to do in today's leetcode challenge.

Always here to assist you guys.

Today's 03-01-24 Problem Link

Intuition

Basic multiplication.

Approach

  • I kept track of number of '1' in a row
  • Now iterated over every row of array
    • counted the number of '1' in current row
    • number of beams will the product of current number of device and previous number of devices
    • added the product to answer
    • now, the current one will become the previous one to next row

Have a look at the code , still have any confusion then please let me know in the comments Keep Solving.:)

Complexity

  • Time complexity : $$O(l)$$

$$l$$ : length of array

  • Space complexity : $$O(1)$$

Code

class Solution {
    public int numberOfBeams(String[] bank) {
        int jawab = 0;      // to store answer
        int picheek = 0;    // to store number of '1' in previous state

        for( String r : bank){
            int ek = (int) r.chars().filter( g -> g == '1').count(); // counting the number of '1' in current row
            if( ek != 0){             // number of beams will the product of current number of device and previous number of devices
                jawab += picheek*ek; // adding the product to answer
                picheek = ek;        // now, the current one will become the previous one to next row
            }
        }
        return jawab;
    }
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy