Codingame - (SG) Java Campaign #4-77019
Codingame - (SG) Java Campaign #4-77019
com)
Campagne : [SG] Java Campaign #4 Langage(s) de programmation : Java Langage : Anglais Date : 28/08/2018
Java 38%
(395 / 1 050)
Design 79%
(230 / 290)
Fiabilité 55%
(68 / 123)
1 / 17
Romdhani ([email protected])
Question 1: Primitive data types
Java 00:13 / 00:20 0 / 40 pts
Question
Among these primitive types, which one(s) exists in Java?
Réponse
int
bool
float
uint
Résultat
Réponse incorrecte
Connaissance du langage +40pts
2 / 17
Romdhani ([email protected])
Question 2: Size of a HashSet
Java 00:21 / 00:30 0 / 40 pts
Question
HashSet s = new HashSet();
s.add(new Integer(1));
s.add(new Integer(1));
s.add(new Integer(2));
Réponse
1
2
3
4
Résultat
Réponse incorrecte
Connaissance du langage +40pts
3 / 17
Romdhani ([email protected])
Question 3: Final method
Java 00:16 / 00:20 20 / 20 pts
Question
A method declared as final means...
Réponse
the method can't be overridden
the method returns a constant
it's impossible: it leads to a compilation error
Résultat
Réponse correcte
Connaissance du langage +20pts
4 / 17
Romdhani ([email protected])
Question 4: HashMap
Java 00:43 / 00:45 0 / 40 pts
Question
HashMap m = new HashMap();
Object o1 = new Object();
Object o2 = o1;
m.put(o1, 1);
m.put(o2, 2);
Réponse
1
2
3
null
Résultat
Réponse incorrecte
Connaissance du langage +40pts
5 / 17
Romdhani ([email protected])
Question 5: Immutable string
Java 00:18 / 00:20 20 / 20 pts
Question
Java strings are immutable.
Réponse
True
False
Résultat
Réponse correcte
Connaissance du langage +20pts
6 / 17
Romdhani ([email protected])
Question 6: BigInteger is immutable
Java 00:25 / 00:25 0 / 60 pts
Question
BigInteger bi = new BigInteger("1");
bi.add(new BigInteger("1"));
Réponse
1
2
11
Résultat
Réponse incorrecte
Connaissance du langage +60pts
7 / 17
Romdhani ([email protected])
Question 7: Use of string buffers/join
Java 02:24 / 05:00 25 / 100 pts
Question
StringUtils.concat(String[] strings) should join character strings end to end.
For example, from an array which contains "f", "o", "o", "bar" it should result "foobar".
Réponse
1 class StringUtils {
2
3 /**
4 * Concatenates the given array of strings.
5 */
6 static String concat(String[] strings) {
7 String s = "" ;
8 for (int i=0 ; i<strings.length ; i++)
9 {
10 s = s.concat(strings[i]) ;
11 }
12 return s ;
13
14 }
15
16 }
Résultat
Strings are correctly joined
Connaissance du langage +25pts
8 / 17
Romdhani ([email protected])
Question 8: From the fruit we know the tree
Java 24:56 / 25:00 0 / 300 pts
Question
A tree is composed of nodes which follow these rules:
A node holds a value corresponding to an integer. Except for the root node of the tree, a node is always
referenced by only one other node. A node has no more than two children. They are called left child
and right child. If a node has no right or left child, the corresponding reference is null. All the
descendants to the left of a node are smaller than the node and all the descendants to the right of the
node are greater than the node.
Here is an example of such a tree (the root node holds the integer 9):
Fig. 1
To simplify things, we combine everything into a single class named Node. The height of the tree is
between 0 and 100 000 nodes (the height of a tree is the length of the path from the root to the
deepest node in the tree). Question: Implement a new Node's method named find(int v) which returns
the node holding the value of v. If the node doesn't exist then find should return null. Important note:
Try to save memory (RAM) space. To test your solution you can use two examples of tree: The variable
small corresponds to the root node of the tree from Fig. 1. The variable large corresponds to the root
node of a tree of height 100 000 nodes. The deepest node holds 0.
9 / 17
Romdhani ([email protected])
Réponse
1 class Node {
2
3 Node left, right;
4 int value;
5 public Node find (int v)
6 { System.out.print(this.value ) ;
7 if (this.value== v)
8 return this ;
9 else if (this.right != null && this.value > v )
10 return this.right.find(v);
11 else if (this.left != null && this.value < v )
12 return this.left.find(v) ;
13 else return null ;
14 }
15
16 }
Résultat
Results are correct with a 'small' tree
Résolution de problèmes +90pts
10 / 17
Romdhani ([email protected])
Question 9: Largest wins from chaos
Java 02:44 / 05:00 100 / 100 pts
Question
Algorithm.findLargest(int[] numbers) should return the largest number from numbers. The array
numbers always contains at least one number.
Réponse
1 class Algorithm {
2
3 /** @return the largest number of the given array */
4 static int findLargest(int[] numbers) {
5 int larg = numbers[0] ;
6
7 for (int i=1 ; i<numbers.length ; i++)
8 {
9 if (larg < numbers[i])
10 larg = numbers[i] ;
11 }
12 return larg ;
13
14 }
15
16 }
Résultat
It works using simple data sample
Résolution de problèmes +32pts
Still works if the largest number is at the last position in the array
Fiabilité +5pts
11 / 17
Romdhani ([email protected])
Question 10: Abstraction
Java 03:48 / 08:00 160 / 200 pts
Question
Try to improve the code displayed in the answer editor by keeping the current behavior of the program.
12 / 17
Romdhani ([email protected])
Réponse
13 / 17
Romdhani ([email protected])
Résultat
Behavior is still correct and Animal.getName is used
Design +160pts
Question
Complete the answer to make the following piece of code valid:
Réponse
1 /** class A */
2 class A {
3
4 }
5
6 /** class B */
7 class B extends A{
8
9 }
Résultat
B extends A
Design +50pts
14 / 17
Romdhani ([email protected])
Question 12: Design pattern 05
Java 00:59 / 01:00 0 / 60 pts
Question
FileInputStream fin = new FileInputStream("X.zip");
BufferedInputStream bin = new BufferedInputStream(fin);
ZipInputStream zin = new ZipInputStream(bin);
Type the name of the design pattern illustrated by this piece of code (1 word only).
Réponse
Heritage
Résultat
Réponse correcte
Design +60pts
Réponse(s) correcte(s)
Decorator
Décorateur
Decorateur
15 / 17
Romdhani ([email protected])
Question 13: The Dependency Inversion Principle (DIP)
Java 00:45 / 00:45 20 / 20 pts
Question
Abstractions should not depend upon details. Details should depend upon abstractions.
Réponse
True
False
Résultat
Réponse correcte
Design +20pts
16 / 17
Romdhani ([email protected])
Glossaire
Connaissance du langage
La mesure de cette compétence permet de déterminer lexpérience du candidat dans la pratique dun langage de
programmation. Privilégiez cette compétence si, par exemple, vous recherchez un développeur qui devra être
rapidement opérationnel.
Design
Cette mesure fournit une indication sur la capacité du candidat à appliquer des solutions standard pour résoudre des
problèmes récurrents. Un développeur ayant un bon niveau dans cette compétence augmentera la qualité
(maintenabilité, évolutivité) de vos applications. Cette compétence ne dépend pas spécifiquement dune technologie.
Privilégiez cette compétence si, par exemple, vous recherchez un développeur qui sera amené à travailler sur les
briques qui structurent vos applications, à anticiper les besoins de demain pour développer des solutions pérennes.
Résolution de problèmes
Cette compétence correspond aux aptitudes du candidat à comprendre et à structurer son raisonnement pour trouver
des solutions à des problèmes complexes. Cette compétence ne dépend pas spécifiquement dune technologie.
Privilégiez cette compétence si, par exemple, vos applications ont une composante technique importante (R&D,
innovation).
Fiabilité
La fiabilité caractérise la capacité du candidat à réaliser des solutions qui prennent en compte les cas particuliers. Plus
cette compétence est élevée, plus vos applications sont robustes (moins de bugs).
17 / 17
Romdhani ([email protected])