Objective Today, we're learning about Interfaces. Check out the Tutorial tab for learning materials and an instructional video! Task The AdvancedArithmetic interface and the method declaration for the abstract divisorSum(n) method are provided for you in the editor below. Complete the implementation of Calculator class, which implements the AdvancedArithmetic interface. The implementation for the divisorSum(n) method must return the sum of all divisors of . Input Format A single line containing an integer, . Constraints Output Format You are not responsible for printing anything to stdout. The locked template code in the editor below will call your code and print the necessary output. Sample Input 6 Sample Output I implemented: AdvancedArithmetic 12 Explanation The integer is evenly divisible by , ,...
Objective Today, we're building on our knowledge of Arrays by adding another dimension. Check out the Tutorial tab for learning materials and an instructional video! 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 hourglass sum. Input Format There are lines of input, where each line contains space-separated integers describing 2D Array ; every value in will be in the inclusive range of to . Constraints Output Format ...
Objective Today, we're discussing a simple sorting algorithm called Bubble Sort . Consider the following version of Bubble Sort: for ( int i = 0 ; i < n ; i ++) { // Track number of elements swapped during a single array traversal int numberOfSwaps = 0 ; for ( int j = 0 ; j < n - 1 ; j ++) { // Swap adjacent elements if they are in decreasing order if ( a [ j ] > a [ j + 1 ]) { swap ( a [ j ], a [ j + 1 ]); numberOfSwaps ++; } } // If no elements were swapped during a traversal, array is sorted if ( numberOfSwaps == 0 ) { break ; } } Task Given an array, , of size distinct elements, sort the array in ascending order using the Bubble Sort algorithm above. Once sorted, print the following lines: Array is sorted in numSwaps swaps. where is the number ...
Comments
Post a Comment