Skip to content

Commit d3059ae

Browse files
author
Iurii Dziuban
committed
updated solutions/explanation/details to all GoogleOnsite2 task
1 parent 8b077d2 commit d3059ae

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

src/main/java/iurii/job/interview/google/GoogleOnsite2.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,6 @@ public Trie get(char c) {
331331
*/
332332
public static Node deleteAllEvenPositionNodes(Node head) {
333333
int len = length(head);
334-
335-
if (head == null) {
336-
System.out.printf("\nList is empty\n");
337-
return null;
338-
}
339-
340334
// if list have single node
341335
// then return
342336
if (len < 2) {
@@ -362,16 +356,13 @@ public static void deleteAllOddPositionNodes(Node head) {
362356
return;
363357
}
364358
Node current = head;
365-
while(true) {
359+
do {
366360
Node toBeDeleted = current.next;
367361
// Note: current.next.next can not be null in circular list.
368362
current.next = current.next.next;
369363
toBeDeleted.next = null;
370364
current = current.next;
371-
if(current == head || current.next == head) {
372-
break;
373-
}
374-
}
365+
} while(current != head && current.next != head);
375366
}
376367

377368
// Function to delete first. returns new head
@@ -419,10 +410,6 @@ private static int length(Node head) {
419410
public static class Node {
420411
Node next;
421412
int val;
422-
423-
String toShortString() {
424-
return String.format("{%d}", val);
425-
}
426413
}
427414

428415
// ========================== End of Task 4.1 ========================================
@@ -671,20 +658,6 @@ public static class GiveCountMessage {
671658
int count;
672659
}
673660

674-
/**
675-
* Simple message
676-
* - senderId to not send message back
677-
* - bunkerIdToCount have set of ids to send across.
678-
* - isLasMessage to send final message from neighbours.
679-
*/
680-
public class Message {
681-
int senderId;
682-
// how to send to next
683-
int ttl;
684-
Map<Integer, Integer> bunkerIdToCount;
685-
boolean isLastMessage;
686-
}
687-
688661
// ========================== End of Task 4.2 ========================================
689662

690663

0 commit comments

Comments
 (0)