๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.59K subscribers
5.59K photos
3 videos
95 files
10.1K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.Scanner;

public class Solution {

    public static int countSundays(int startYear, int endYear) {
        int answer = 0;
        int day = 1;

        for (int year = 1900; year < startYear; year++) {
            for (int month = 1; month <= 12; month++) {
                day = (day + daysInMonth(month, year)) % 7;
            }
        }

        for (int year = startYear; year <= endYear; year++) {
            for (int month = 1; month <= 12; month++) {
                if (day == 0) {
                    answer++;
                }
                day = (day + daysInMonth(month, year)) % 7;
            }
        }

        return answer;
    }

    private static int daysInMonth(int month, int year) {
        switch (month) {
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            case 2:
                if (isLeapYear(year)) {
                    return 29;
                } else {
                    return 28;
                }
            default:
                return 31;
        }
    }

    private static boolean isLeapYear(int year) {
        if (year % 4 != 0) {
            return false;
        } else if (year % 100 != 0) {
            return true;
        } else if (year % 400 != 0) {
            return false;
        } else {
            return true;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int startYear = in.nextInt();
        int endYear = in.nextInt();

        int result = countSundays(startYear, endYear);
        System.out.print(result);
    }
}

Well fargo |javaโœ…
Scanner scanner = new Scanner(System.in);
        int numOfProducts = scanner.nextInt();
        int[] orders = new int[numOfProducts];

        for (int i = 0; i < numOfProducts; i++) {
            orders[i] = Math.abs(scanner.nextInt());
        }

        int disAmount = scanner.nextInt();
        int count = 0;

        for (int order : orders) {
            if (disAmount % order == 0) {
                count++;
            }
        }

        System.out.println(count);  

Wells Fargo Javaโœ…
๐Ÿ‘1
string getLongestRegex(string a, string b, string c)
{
  const size_t n = a.size();
  int idx = -1;
  for (int i = 0; i < n; i++) {
    if (c[i] != a[i] && c[i] != b[i]) { idx = i; }
  }
  if (idx == -1) return "-1";
  string res;
  for (int i = 0; i < n; i++) {
   
    if (i == idx) {
      string cur = "[";
      for (int j = 'A'; j <= 'Z'; j++)  if (j != c[i]) cur += j;
      cur += "]";
      res += cur;
    } else {
      res += "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]";
    }
  }
  return res;
}


C++โœ…
def minimumCost(price):
    n = len(price)
    price.append(0)
    ans = float('inf')
    last = {price[0]: 0}
    for i in range(1, n):
        v = price[i]
        price[i] += price[i - 1]
        if last.get(v) != None:
            ans = min(ans, price[i] - price[last[v]] + v)
        last[v] = i
    return ans if ans != float('inf') else -1

n = int(input())
price = list(map(int,input().split(' ')))
print(minimumCost(price))

Python 3โœ…
Amazon