Skip to main content

Featured

Adobe Experience Manager - Create an OSGI Configuration

 In this article, let's create an OSGi configuration, configure it and use it in AEM code. So now let's get started with the creation of an OSGi configuration. Technical details and Assumptions: All the following details are tested in AEM version 6.5.8, Java version 11.0.2 Creation of OSGi configuration: To create an OSGi configuration we need to create an ObjectClassDefinition. I have included a sample OCD configuration, which can be used as a reference to create one. The next step would be to create an interface and an implementation that can help fetch the OSGi configurations.  Interface: Implementation: Let's try to use the OSGi configuration created so far in Models/Servlets. For demonstration purposes, I used AEM Models here, but the same can be implemented in Servlets too. Now that we have created the OSGi configuration. Once building the code, we should be able to see the OSGi configuration in the web console (http://localhost:4502/system/console/configMgr) C...

Migratory Birds

A flock of birds is flying across the continent. Each bird has a type, and the different types are designated by the ID numbers , , , , and .

Given an array of integers where each integer describes the type of a bird in the flock, find and print the type number of the most common bird. If two or more types of birds are equally common, choose the type with the smallest ID number.

Input Format

The first line contains an integer denoting (the number of birds).

The second line contains space-separated integers describing the respective type numbers of each bird in the flock.

Constraints


It is guaranteed that each type is , , , , or .

Output Format

Print the type number of the most common bird; if two or more types of birds are equally common, choose the type with the smallest ID number.

Sample Input 0
6
1 4 4 4 5 3
Sample Output 0
4

Explanation 0

Type 1: 1 bird
Type 2: 0 birds
Type 3: 1 bird
Type 4: 3birds
Type 5: 1 bird

The type number that occurs at the highest frequency is type 4 so we print 4 as our answer.
Program
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    static int migratoryBirds(int n, int[] ar) {
     int ary[] = new int[n];
        for(int i = 0; i < n ; i++ )
        ary[ar[i]]++; 
        int max = 0,maxpos=0;
        for(int i = 0 ; i < n ; i++)
            {
            if(ary[i] > max)
                {
                max = ary[i];
                maxpos = i;
            }
        }
        return maxpos;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] ar = new int[n];
        for(int ar_i = 0; ar_i < n; ar_i++){
            ar[ar_i] = in.nextInt();
        }
        int result = migratoryBirds(n, ar);
        System.out.println(result);
    }
}

Comments

Popular Posts