Sort by

recency

|

3094 Discussions

|

  • + 0 comments

    Really cool seeing so many clean solutions here — the sliding window approach seems to be the favorite, and for good reason. It’s efficient, easy to grasp once you visualize how the window moves, and works perfectly for problems like “Birthday Chocolate.”

    What I find fascinating is how algorithmic problem-solving trains your brain for real-world analysis — Each move (or loop) has a purpose, and small optimizations make a big difference. Speaking of that, I recently read about the an event, which highlighted how mental precision and strategy are just as important as physical strength — a lot like writing efficient code.

  • + 0 comments

    Good challenge. Also, I found this tool that gives a very detailed analysis of my resume and suggests amazing improvements: www.autointerviewai.com/ats-score . You guys might wanna check it out!

  • + 0 comments

    Java Solution

    Using Sliding Window Protocal O(n)

     public static int birthday(List<Integer> s, int d, int m) {
        // Write your code here
            int count = 0 ;
            
            int sum = 0 ;
            for(int i = 0 ; i < m ; i++){
                sum += s.get(i);
            }
            if(sum == d){
                count++;
            }
            
            for(int i = m ; i < s.size() ; i ++){
                sum = sum - s.get(i-m) + s.get(i);
                if(sum == d){
                    count++;
                }
            }
            return count;
        }
    
  • + 2 comments

    TypeScript ugly one-liner:

    function birthday(s: number[], d: number, m: number): number {
      return s.flatMap((_, i) => [s.slice(i, m + i)]).filter((arr) => arr.reduce((a, b) => a + b, 0) === d).length;
    }
    
  • + 1 comment
    int birthday(vector<int> s, int d, int m) {
        std::vector<int>::iterator left = s.begin();
        std::vector<int>::iterator right = left + m; // points behind sliding window
        
        int sum = std::accumulate(left, right, 0);
        int numWays = sum == d ? 1 : 0;
        
        while (right != s.end()) {
            sum = sum - *left + *right; // update sum
            left++; right++; // and move the sliding window
            
            if (sum == d)
                numWays++;
        }
        
        return numWays;
    }