1.

/*
* ACM Contest training
* Problem: 902 - Password Search
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=11&problem=843
*
* @author Christoph Goettschkes
* @version 1.0, 01/06/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.732
*/

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

while (input.hasNext()) {
int pwLength = input.nextInt();
String str = input.next();
HashMap<String, Integer> m = new HashMap<String, Integer>();

for (int i = 0; i < str.length() - pwLength + 1; i++) {
String subs = str.substring(i, i + pwLength);
if (m.containsKey(subs)) {
m.put(subs, m.get(subs) + 1);
} else {
m.put(subs, 1);
}
}

String ret = "";
int max = Integer.MIN_VALUE;

for (Map.Entry<String, Integer> k : m.entrySet()) {
String key = k.getKey();
int val = k.getValue();

if (val > max) {
max = val;
ret = key;
}
}

System.out.println(ret);
}
}
}

2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 902 Password Search
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=843
*
* @author Siegfried Ippisch
* @author Martin Lambeck
* @version 1.0, 09/06/2010
*
* Method : Strings
* Status : Accepted
* Runtime: 1.568
*/

import java.util.*;

public class Main {

private static String searchPassword(int n, String text){
Map<String, Integer> map = new HashMap<String, Integer>();
for(int i=0; i<=text.length()-n; i++){
String sub = text.substring(i, i+n);
if(map.containsKey(sub))
map.put(sub,map.get(sub)+1);
else
map.put(sub,1);
}
Map.Entry<String, Integer> result = null;
for(Map.Entry<String, Integer> e: map.entrySet()){
if(result == null || e.getValue() > result.getValue())
result = e;
}
return result.getKey();
}

public static void main(String[] args){
Scanner input = new Scanner(System.in);

while(input.hasNext()){
System.out.println(searchPassword(input.nextInt(),input.next()));
}

}

}