Sort by

recency

|

3076 Discussions

|

  • + 1 comment
    def birthday(s, d, m):
        ways = 0
        for i in range(0, len(s)):
            if sum(s[i:i + m]) == d: ways += 1
        return ways
    
  • + 0 comments

    using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Text.RegularExpressions; using System.Text; using System;

    class Result {

    /*
     * Complete the 'birthday' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts following parameters:
     *  1. INTEGER_ARRAY s
     *  2. INTEGER d
     *  3. INTEGER m
     */
    
    public static int birthday(List<int> s, int d, int m)
    {
      int count = 0;
        int len = s.Count;
        // Loop through the list
        for (int i = 0; i <= len - m; i++)
        {
            int sum = 0;
            // Calculate the sum of the next m elements
            for (int j = 0; j < m; j++)
            {
                sum += s[i + j];
            }
            // Check if the sum equals d
            if (sum == d)
            {
                count++;
            }
        }
        return count;
    }
    

    }

    class Solution { public static void Main(string[] args) { TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

        int n = Convert.ToInt32(Console.ReadLine().Trim());
    
        List<int> s = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(sTemp => Convert.ToInt32(sTemp)).ToList();
    
        string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' ');
    
        int d = Convert.ToInt32(firstMultipleInput[0]);
    
        int m = Convert.ToInt32(firstMultipleInput[1]);
    
        int result = Result.birthday(s, d, m);
    
        textWriter.WriteLine(result);
    
        textWriter.Flush();
        textWriter.Close();
    }
    

    }

  • + 0 comments

    for debugging added console write line message its but its not helping to debug in dotnet . pls do let me know if there Is there a way to log

  • + 0 comments
    int birthday(vector<int> s, int d, int m) {
        int re=0;
        for(int i=0;i<s.size();i++){
            int sum=0;
            for(int j=0;j<m;j++){
                sum=sum+s[i+j];
            }
            if(sum==d && re==re)re++;
        }
        return re;
    
    }
    
  • + 0 comments

    I’ve been following the subarray division discussions closely, and it’s interesting how similar the concept is to planning stages in grand building construction. Just like dividing an array into segments that meet certain conditions, architects often break down massive projects into structured phases where each part contributes to the strength and functionality of the whole. Whether it’s optimizing a subarray to meet a sum or segmenting construction tasks to maintain flow and balance, both require precision, foresight, and smart allocation of resources.