You are viewing a single comment's thread. Return to all comments →
C# using a dictionary:
public static long arrayManipulation(int n, List<List<int>> queries) { Dictionary<long, long> hash = new Dictionary<long, long>(); long max = long.MinValue; for (int i = 0; i < queries.Count; i++) { if (hash.ContainsKey(queries[i][0])) hash[queries[i][0]] += queries[i][2]; else hash[queries[i][0]] = queries[i][2]; if (hash.ContainsKey(queries[i][1] + 1)) hash[queries[i][1] + 1] -= queries[i][2]; else hash[queries[i][1] + 1] = queries[i][2] * -1; } long val = 0; for (int i = 0; i <= n; i++) { val += hash.ContainsKey(i) ? hash[i]: 0; max = Math.Max(val, max); } return max; }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
C# using a dictionary: