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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Arrays
  4. Array Manipulation
  5. Discussions

Array Manipulation

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • nxhao3003
    3 months ago+ 0 comments

    java 8

        public static long arrayManipulation(int n, List<List<Integer>> queries) {
            long[] answer = new long[n + 2];
            long maxSum = Long.MIN_VALUE;
            for (int i = 0; i < queries.size(); i++) {
                int a = queries.get(i).get(0);
                int b = queries.get(i).get(1);
                int k = queries.get(i).get(2);
                answer[a - 1] += k;
                answer[b] -= k;
            }
            long currLong = 0L;
            for (int i = 0; i < answer.length; i++) {
                currLong += answer[i];
                maxSum = Math.max(currLong, maxSum);
            }
            return maxSum;
        }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy