IBM HACKERRANK CODING SOLUTIONS
رفتن به کانال در Telegram
We provide help for all Exams... Anyone can contact me @AK_Coder for Exam clearance and interviews Trusted ✅
نمایش بیشترکشور مشخص نشده استدسته بندی مشخص نشده است
4 420
مشترکین
اطلاعاتی وجود ندارد24 ساعت
اطلاعاتی وجود ندارد7 روز
اطلاعاتی وجود ندارد30 روز
آرشیو پست ها
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));
}
}
This is how we help in premium group🤩 💯✨
🔴This was previous IRA that was on 2nd may
🔴Without single error in code..given💯💯
Just 100% results given for 2nd May
🚨if anyone need help for tomorrow IRA ping me @bulliea to join 9nd May premium group
