We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Superman Celebrates Diwali
  5. Discussions

Superman Celebrates Diwali

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 25 Discussions, By:

recency

Please Login in order to post a comment

  • thecodingsoluti2
    2 months ago+ 0 comments

    Here is superman Celebrates Diwali problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-superman-celebrates-diwali-problem-solution.html

    0|
    Permalink
  • isudnik
    1 year ago+ 0 comments

    I don't understand what input/output logic expected. Every previous task provides function name and parameters. Here we don't have anything

    0|
    Permalink
  • sukhesai
    1 year ago+ 0 comments

    typical dp problem with some tricky manipulation. Here is my python solution:

    import collections
    
    
    n,h,ii = map(int, input().split())
    dp = [[0]*h for _ in range(n)]
    for i in range(n):
        x = list(map(int, input().split()))
        for j in x[1:]: dp[i][j-1] += 1
    last = collections.deque()
    for j in range(h):
        x = last.popleft() if j >= ii else 0
        for i in range(n):
            dp[i][j] += max(0 if j == 0 else dp[i][j-1], x)
        last.append(max(k[j] for k in dp))
    print(max(k[-1] for k in dp))
    
    0|
    Permalink
  • chandrasekharka5
    2 years ago+ 0 comments

    import java.io.IOException; import java.io.InputStream;

    public class Solution {

    public static void main(String[] args) throws IOException {
        InputReader reader = new InputReader(System.in);
        int N = reader.readInt();
        int H = reader.readInt();
        int I = reader.readInt();
    

    int[][] people = new int[N][H]; for (int n=0; n

    } int[][] save = new int[N][H]; int[] max = new int[H]; for (int n=0; n

    } for (int h=1; h= I) { value = Math.max(value, max[h-I]);

    } value += people[n][h]; maxPeople = Math.max(maxPeople, value); save[n][h] = value; } max[h] = maxPeople;

    } int answer = 0; for (int n=0; n

    static final class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
    
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
    
    
        private int read() throws IOException {
            if (curChar >= numChars) {
                curChar = 0;
                numChars = stream.read(buf);
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
    
                }
    
        public final int readInt() throws IOException {
            return (int)readLong();
    
                }
    
        public final long readLong() throws IOException {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
                if (c == -1) throw new IOException();
    
                }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
    
    
                }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
    
    
                c = read();
            } while (!isSpaceChar(c));
            return negative ? -res : res;
    
                }
    
        public final int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i=0; i<size; i++) {
                array[i] = readInt();
            }
            return array;
    
                }
    
        public final long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i=0; i<size; i++) {
                array[i] = readLong();
            }
            return array;
        }
    
    
        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
    

    }

    0|
    Permalink
  • TChalla
    2 years ago+ 0 comments

    Python solution

    n, h, hl = map(int, input().split())
    cnt = f = [[0 for _ in range(1901)] for _ in range(1900)]
    g = [0 for _ in range(1901)]
    for ctr in range(n):
        lis = list(map(int, input().split()))
        for j in range(1, len(lis)):
            cnt[ctr][lis[j]] += 1
    for ctr in range(n):
        f[ctr][h] = cnt[ctr][h]
        if f[ctr][h] > g[h]:
            g[h] = f[ctr][h]
    for j in range(h - 1, -1, -1):
        for i in range(n):
            tmp = 0
            if j + hl <= h:
                if g[j + hl] > tmp: 
                    tmp = g[j + hl]
            if f[i][j + 1] > tmp: 
                tmp = f[i][j + 1]
            f[i][j] = tmp + cnt[i][j]
            if f[i][j] > g[j]:
                g[j] = f[i][j]
    ans = 0
    for ctr in range(n):
        ans = max(ans, f[ctr][0])
    print(ans)
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy