Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
107 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
Strange Alchemist's user avatar
2 votes
1 answer
559 views

Speeding up a recursive Cantor pairing function

The Cantor Pairing function is a mathematical function which takes two integers and combines them into a single integer that is unique to that pair. This single integer can later be "unpaired" back ...
HomeworkHopper's user avatar
3 votes
1 answer
672 views

Checking whether given array is sorted by divide-and-conquer

I've written a code that I try to use divide and conquer approach to determine if the given array is sorted. I wonder whether I apply the approach accurately. ...
Soner from The Ottoman Empire's user avatar
1 vote
1 answer
500 views

Counting contiguous subarrays with a negative sum

I'm doing a coding challenge that asks to count the number of contiguous subarrays that have a negative sum: A subarray of an n-element array is an array composed from a contiguous block of the ...
Richard's user avatar
  • 171
3 votes
2 answers
392 views

Check whether array is sorted recursively

I'm trying to implement isSorted method checking whether given array is sorted recursively. I've written two types, one is similar to merge sort logic, the another ...
Soner from The Ottoman Empire's user avatar
3 votes
1 answer
446 views

Find the maximum possible summation of differences of consecutive elements

Array A contains the elements, \$A_1,A_2, \ldots, A_N\$. And array B contains the elements, \$B_1,B_2, \ldots, B_N\$. There is a relationship between \$A_i\$ and \$B_i\$: any element \$A_i\$ ...
kumarmo2's user avatar
  • 261
2 votes
2 answers
2k views

Exercise - Break an array into n equal or almost-equal sized parts recursively to find maximum

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. The exercise (translation): Change ...
Philipp Doerner's user avatar
2 votes
1 answer
8k views

Fill 2D array recursively

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and I'm trying to solve one of the exercises there. Problem Statement The exercise ...
Philipp Doerner's user avatar
1 vote
1 answer
318 views

Add 1 to a number represented as an array of digits, using recursion

Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. Explanation for using ...
clever_bassi's user avatar
8 votes
2 answers
8k views

Recursively evaluate neighbors in a two dimensional grid

I'm creating a puzzle mini game where there is a board of gems, varying in color, and chosen at random. This is what my code generates: When you click on a gem the game should traverse the board and ...
Nick Savage's user avatar
2 votes
0 answers
335 views

Find the most efficient combination that equals target number in ArrayList

I want to implement the following function: Given a target sum, return the combination that equals the target sum and is the most efficiënt combination in the array of an ...
ewart's user avatar
  • 21
5 votes
3 answers
2k views

Merge Sort Implementation in Java (that seems slow...)

I decided to write my own implementation of merge sort. Here is the code: ...
TheCoffeeCup's user avatar
  • 9,486
30 votes
3 answers
83k views

Find all subsets of an int array whose sums equal a given target

I am trying to implement a function below: Given a target sum, populate all subsets, whose sum is equal to the target sum, from an int array. For example: Target ...
Mengjun's user avatar
  • 403
6 votes
4 answers
19k views

Getting the largest element in an array using recursion

Any suggestions on how to make this code more efficient? ...
NYC Canuck's user avatar