하이퍼커넥트에서 코딩 테스트를 봤다. 생각보다 쉬웠는데.. 마지막 문제에서 performance 에서 걸려서.. 제 시간안에 못풀었다. 결과는 74점으로 탈락 예상이 된다…ㅜㅜ
문제는 총 7문제로, 다지선다 2문제, java 코딩 5문제로 구성되어있었다.
class Platformer {
private ListIterator<Integer> tilesItor;
private int current;
public Platformer(int n, int position) {
//throw new UnsupportedOperationException("Waiting to be implemented.");
List<Integer> tiles = new LinkedList<>();
for(int i=0; i<n; i++) {
tiles.add(i);
}
this.tilesItor = tiles.listIterator();
for(int i=0; i<position; i++) {
this.tilesItor.next();
}
this.current = this.tilesItor.next();
}
public void jumpLeft() {
//throw new UnsupportedOperationException("Waiting to be implemented.");
this.tilesItor.remove();
this.tilesItor.previous();
this.current = this.tilesItor.previous();
}
public void jumpRight() {
//throw new UnsupportedOperationException("Waiting to be implemented.");
this.tilesItor.remove();
this.tilesItor.next();
this.current = this.tilesItor.next();
}
public int position() {
//throw new UnsupportedOperationException("Waiting to be implemented.");
return this.current;
}
}
@Test
public void main() {
Platformer platformer = new Platformer(6, 3);
System.out.println(platformer.position()); // should print 3
platformer.jumpLeft();
System.out.println(platformer.position()); // should print 1
platformer.jumpRight();
System.out.println(platformer.position()); // should print 4
}