IBM HACKERRANK CODING SOLUTIONS
Ir al canal en Telegram
We provide help for all Exams... Anyone can contact me @AK_Coder for Exam clearance and interviews Trusted ✅
Mostrar másEl país no está especificadoLa categoría no está especificada
4 420
Suscriptores
Sin datos24 horas
Sin datos7 días
Sin datos30 días
Archivo de publicaciones
Ss, your message was hidden, forwards not allowed in this group.
import java.util.*;
import java.math.*;
class GFG
{
// Function to maximise the sum of selected numbers
//by deleting occurrences of Ai-1 and Ai+1
public static int getMaximumSum (int arr[]) {
// Number of elements in the array
int n = arr.length;
// Largest element in the array
int max = -1;
for(int i = 0; i < n; i++)
{
max = Math.max(max, arr[i]);
}
// An array to count the occurrence of each element
int []freq = new int[max + 1];
for(int i = 0; i < n; i++)
{
freq[arr[i]]++;
}
// ans to store the result
int ans = 0, i=max;
// Using the above mentioned approach
while(i>0){
// if occurence is greater than 0
if(freq[i] > 0){
// add it to ans
ans += i;
// decrease i-1th element by 1
freq[i-1]--;
// decrease ith element by 1
freq[i]--;
}else{
// decrease i
i--;
}
}
return ans;
}
public static void main(String[] args)
{
int []a = {1, 2, 3};
System.out.println(getMaximumSum(a));
}
}
🚨Guys anyone need help in
✨ Wiley Edge | Barclays |Hexaware | TCS DIGITAL wing 1 / DCA and 𝗮𝗻𝘆 placement Exam ( any company )
💯% clearance will be given
✨contact : @AK_Coder
✅👇Join for job updates and for help @+M-ulHt3W-882MGY1
Bujji, your message was hidden, forwards not allowed in this group.
