본문 바로가기

Is This a Binary Search Tree? (Java) Write a function that takes a binary tree and returns true if it is a binary search tree, and false if not.In our test code, we're going to use the following examples:head1 = 0 / \ 1 2 /\ /\ 3 4 5 6head1 is NOT a binary search tree.head2 = 3 / \ 1 4 /\ / \ 0 2 5 6head2 is NOT a binary search tree.head3 = 3 / \ 1 5 /\ / \ 0 2 4 6head3 is a binary search tree.head4 = 3 / \ 1 5 /\ 0 4head4 is NOT a.. 더보기
N-th Element of a Linked List (Java) Implement a function that finds the nth node in a linked list, counting from the end.Your function should take a linked list (its head element) and n, a positive integer as its arguments.Examples:head = 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1 -> (null / None)The third element of head counting from the end is 3.head2 = 1 -> 2 -> 3 -> 4 -> (null / None)The fourth element of head2 counting from the end is .. 더보기
Rotating a 2D Array by 90 Degrees - In Place (Java) A 2-dimensional array is an array of arrays.Implement a function that takes a square 2D array (# columns = # rows) and rotates it by 90 degrees.Example: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]->[[7, 4, 1], [8, 5, 2], [9, 6, 3]]When you are done, try implementing this function so that you can solve this problem in place. Solving it in place means that your function won't create a new array to solve thi.. 더보기
Rotating a 2D Array by 90 Degrees (Java) A 2-dimensional array is an array of arrays.Implement a function that takes a square 2D array (# columns = # rows) and rotates it by 90 degrees.Example: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]->[[7, 4, 1], [8, 5, 2], [9, 6, 3]]When you are done, try implementing this function so that you can solve this problem in place. Solving it in place means that your function won't create a new array to solve thi.. 더보기
Find Where to Expand in Minesweeper (Java) Implement a function that turns revealed cells into -2 given a location the user wants to click.For simplicity, only reveal cells that have 0 in them. If the user clicks on any other type of cell (for example, -1 / bomb or 1, 2, or 3), just ignore the click and return the original field. If a user clicks 0, reveal all other 0's that are connected to it.Example 1: Given field: [[0, 0, 0, 0, 0], [.. 더보기
Assign Numbers in Minesweeper (Java) Implement a function that assigns correct numbers in a field of Minesweeper, which is represented as a 2 dimensional array.Example: The size of the field is 3x4, and there are bombs at the positions [0, 0] (row index = 0, column index = 0) and [0, 1] (row index = 0, column index = 1).Then, the resulting field should be:[[-1, -1, 1, 0], [2, 2, 1, 0], [0, 0, 0, 0]] Your function should return the .. 더보기
One Away Strings (Java) Write a function that takes two strings and returns true if they are one away from each other.They are one away from each other if a single operation (changing a character, deleting a character or adding a character) will change one of the strings to the other.Examples:"abcde" and "abcd" are one away (deleting a character)."a" and "a" are one away (changing the only character 'a' to the equivale.. 더보기
Non-Repeating Character (Java) Implement a function that takes a string and returns the first character that does not appear twice or more.Example:"abacc" -> 'b' ('a' appears twice, and so does 'c')"xxyzx" -> 'y' ('y' and 'z' are non-repeating characters, and 'y' appears first)If there is no non-repeating character, return null. 풀이 import java.util.*; public class NR { public static void main(String[] args) { // NOTE: The fol.. 더보기
Is One Array a Rotation of Another? (Java) Write a function that returns true if one array is a rotation of another.NOTE: There are no duplicates in each of these arrays. Example: [1, 2, 3, 4, 5, 6, 7] is a rotation of [4, 5, 6, 7, 1, 2, 3]. 풀이 import java.util.List;import java.util.ArrayList;import java.util.Arrays; public class IR { public static void main(String[] args) { // NOTE: The following input values will be used for testing yo.. 더보기
Common Elements in Two Sorted Arrays (Java) Write a function that returns the common elements (as an array) between two sorted arrays of integers (ascending order).Example: The common elements between [1, 3, 4, 6, 7, 9] and [1, 2, 4, 5, 9, 10] are [1, 4, 9]. 풀이 import java.util.ArrayList;import java.util.HashMap;import java.util.List; public class CE { public static void main(String[] args) { // NOTE: The following input values are used f.. 더보기