Category: maths-power

Mean of fourth powers of first N natural numbers

Mean of fourth powers of first N natural numbersGiven a positive integer N, the task is to find the average of the fourth powers of the first N natural numbers.Examples:Input: N = 3Output: 32.6667Explanation:Sum of the fourth powers of the first N natural numbers = 14 + 24 + 34 = 1 + 16 + […]

Continue Reading

Sort array of strings after sorting each string after removing characters whose frequencies are not a powers of 2

import java.io.*;import java.lang.*;import java.util.*;class GFG{static boolean isPowerOfTwo(int n){             if (n == 0)        return false;        return (Math.ceil(Math.log(n) / Math.log(2)) ==           Math.floor(Math.log(n) / Math.log(2)));}static void printArray(ArrayList res){             Collections.sort(res);        for(int i = 0; i < res.size(); i++)    {        System.out.print(res.get(i) + " ");    }}static void sortedStrings(String S[], int N){                 HashMap freq = new HashMap();            ArrayList res = new ArrayList();        for(int i = 0; i < N; i++)    {                         String st = "";                        for(int j […]

Continue Reading