TopcoderArchive
Archive
Algorithm problem

SevenDwarfs

Problem statement, definition, constraints, and public examples.

Problem Statement

You are at a convention of magic beings. You would like to locate the famous Seven Dwarfs, but you have no idea what they look like. To make matters worse, the convention is full of various hobbits, gnomes and other similar creatures.

The feature that can help you identify the Seven Dwarfs is that they all have the same height. You know there's exactly seven of them, and you are going to make the assumption that (due to legal reasons) no other creature has exactly the same height as the Seven Dwarfs.

You are given the names and heights of all the beings at the convention: for each valid i, creature i is called name[i] and it is height[i] centimeters tall.

Return a String[] with the names of the Seven Dwarfs in sorted order. The input will be such that the output is always unique.

Definition

Class:
SevenDwarfs
Method:
findThem
Parameters:
String[], int[]
Returns:
String[]
Method signature:
String[] findThem(String[] name, int[] height)
(be sure your method is public)

Constraints

  • name will contain between 1 and 100 elements, inclusive.
  • Each element of name will have between 1 and 10 characters.
  • Each character in name will be an English letter ('A'-'Z', 'a'-'z').
  • height will contain the same number of elements as name
  • Each element of height will be between 1 and 1000, inclusive.
  • There will be a unique value with exactly seven occurrences in height.

Examples

  1. {"Doc", "Grumpy", "Happy", "SnowWhite", "Sleepy", "Bashful", "Sneezy", "Dopey"}
    {105, 105, 105, 163, 105, 105, 105, 105}
    Returns: {"Bashful", "Doc", "Dopey", "Grumpy", "Happy", "Sleepy", "Sneezy" }
  2. {"Adam", "bobby", "Cecil", "david", "Emile", "friedrich", "Gunnar"}
    {47, 47, 47, 47, 47, 47, 47}
    Returns: {"Adam", "Cecil", "Emile", "Gunnar", "bobby", "david", "friedrich" }
    Use standard ASCII character codes when sorting the dwarfs' names: 'Z' comes before 'a'.
  3. {"Dwarf", "Dwarf", "Dwarf", "Hobbit", "Dwarf", "Giant", "Goblin", "Dwarf", "Dwarf", "Hobbit", "Dwarf", "Dwarf"}
    {83, 83, 83, 102, 83, 347, 99, 83, 83, 105, 353, 83}
    Returns: {"Dwarf", "Dwarf", "Dwarf", "Dwarf", "Dwarf", "Dwarf", "Dwarf" }
    Multiple creatures may share the same name. Not all creatures with the same name have to also share the same height. (E.g., note that there are eight creatures called "Dwarf" in this input, but only seven of them are the dwarfs we are looking for, the other one is over 3 meters tall.)
Back to all problems