title-img


Java 2D Array

You are given a 6*6 2D array. An hourglass in an array is a portion shaped like this: a b c d e f g For example, if we create an hourglass using the number 1 within an array full of zeros, it may look like this: 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 Actually, there are many hourglasses in the array above. The three leftmost hourglasses are the following: 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 0 Th

View Solution →

Java Subarray

We define the following: A subarray of an n-element array is an array composed from a contiguous block of the original array's elements. For example, if array=[1,2,3], then the subarrays are [1], [2], [3], [1,2], [2,3], and [1,2,3]. Something like [1,3] would not be a subarray as it's not a contiguous subsection of the original array. The sum of an array is the total sum of its elements. An array's sum is negative if the total sum of its elements is negative. An array's su

View Solution →

Java Arraylist

Sometimes it's better to use dynamic size arrays. Java's Arraylist can provide you this feature. Try to solve this problem using Arraylist. You are given n lines. In each line there are zero or more integers. You need to answer a few queries where you need to tell the number located in yth position of xth line. Take your input from System.in. Input Format The first line has an integer n. In each of the next n lines there will be an integer d denoting number of integers on that line and

View Solution →

Java 1D Array (Part 2)

Let's play a game on an array! You're standing at index 0 of an n-element array named game. From some index i (where 0<=i<n), you can perform one of the following moves: Move Backward: If cell i-1 exists and contains a 0, you can walk back to cell i-1. Move Forward: If cell i+1 contains a zero, you can walk to cell i+1. If cell i+leap contains a zero, you can jump to cell i+leap. If you're standing in cell n-1 or the value of i+leap>=n, you can walk or jump off

View Solution →

Java List

For this problem, we have 2 types of queries you can perform on a List: 1.Insert y at index x: Insert x y 2.Delete the element at index x: Delete x Given a list, L, of N integers, perform Q queries on the list. Once all queries are completed, print the modified list as a single line of space-separated integers. Input Format The first line contains an integer, N(the initial number of elements in L). The second line contains N space-separated integers descri

View Solution →