본문 바로가기

Left Rotation A left rotation operation on an array of size shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become .Given an array of integers and a number, , perform left rotations on the array. Then print the updated array as a single line of space-separated integers.Input FormatThe first line contains two space-separated int.. 더보기
Dynamic Array Create a list, , of empty sequences, where each sequence is indexed from to . The elements within each of the sequences also use -indexing.Create an integer, , and initialize it to .The types of queries that can be performed on your list of sequences () are described below:Query: 1 x yFind the sequence, , at index in .Append integer to sequence .Query: 2 x yFind the sequence, , at index in .Find.. 더보기
2D Array - DS Context Given a 2D Array, :1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 We define an hourglass in to be a subset of values with indices falling in this pattern in 's graphical representation:a b c d e f g There are hourglasses in , and an hourglass sum is the sum of an hourglass' values.Task Calculate the hourglass sum for every hourglass in , then print the maximum ho.. 더보기
Arrays - DS An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, , of size , each memory location has some unique index, (where ), that can be referenced as (you may also see it written as ).Given an array, , of integers, print each element in reverse order as a single line of space-separated integers.Note: If you've already solved our C++ .. 더보기
Sorting: Bubble Sort Consider the following version of Bubble Sort:for (int i = 0; i a[j+1]){ int tmp = a[j+1]; a[j+1] = a[j]; a[j] = tmp; count++; } } } System.out.println("Array is sorted in " + count + " swaps."); System.out.println("First Element: " + a[0]); System.out.println("Last Element: " + a[a.length-1]); } } 더보기
Heaps: Find the Running Median The median of a dataset of integers is the midpoint value of the dataset for which an equal number of integers are less than and greater than the value. To find the median, you must first sort your dataset of integers in non-decreasing order, then:If your dataset contains an odd number of elements, the median is the middle element of the sorted sample. In the sorted dataset , is the median.If yo.. 더보기
Level 4- 땅따먹기 게임 영희는 땅따먹기 게임에 푹 빠졌습니다. 땅따먹기 게임의 땅은 총 N행 4열로 나누어져 있고, 모든 칸에는 점수가 쓰여 있습니다. 땅을 밟으면서 한 행씩 내려올 때, 영희는 각 행의 4칸 중 1칸만 밟으면서 내려올 수 있습니다. 땅따먹기 게임에는 같은 열을 연속해서 밟을 수가 없는 특수 규칙이 있습니다. 즉, 1행에서 (5)를 밟았다면, 2행의 (8)은 밟을 수가 없게 됩니다. 마지막 행까지 모두 내려왔을 때, 점수가 가장 높은 사람이 게임의 승자가 됩니다. 여러분이 hopscotch 함수를 제작하여 영희가 최대 몇 점을 얻을 수 있는지 알려주세요. 예를 들어 1 2 3 5 5 6 7 8 4 3 2 1 의 땅이 있다면, 영희는 각 줄에서 (5), (7), (4) 땅을 밟아 16점을 최고점으로 받을 수 있으.. 더보기
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.. 더보기