Array Problems
Problem 1: Maximum Consecutive gap
- Given an unsorted integer array A of size N. Find the maximum difference between the successive elements in its sorted form.
- You may assume that all the elements in the array are non-negative integers and fit in the 32-bit signed integer range. You may also assume that the difference will not overflow.
- Return 0 if the array contains less than 2 elements.
class Solution:
# @param A : tuple of integers
# @return an integer
def maximumGap(self, A):
B = sorted(A)
mx = 0
for i in range(len(B)-1):
mx = max(mx, abs(B[i]-B[i+1]))
return mx
class Hello{
public static void main(String args[]){
System.out.println("Hello World!")
}
}
Hello There General Kenobi
- Given an unsorted integer array A of size N. Find the maximum difference between the successive elements in its sorted form.
- You may assume that all the elements in the array are non-negative integers and fit in the 32-bit signed integer range. You may also assume that the difference will not overflow.
- Return 0 if the array contains less than 2 elements.
class Solution:
# @param A : tuple of integers
# @return an integer
def maximumGap(self, A):
B = sorted(A)
mx = 0
for i in range(len(B)-1):
mx = max(mx, abs(B[i]-B[i+1]))
return mx
class Hello{
public static void main(String args[]){
System.out.println("Hello World!")
}
}