All Questions
15 questions
5votes
3answers
959views
LeetCode 678: Valid Parenthesis String, Recursion memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working, but I want to improve it. The challenge I am facing is ...
2votes
3answers
553views
Recursive palindrome check
I'm trying to solve this which basically calls for a recursive palindrome check with some minor extra steps (Special characters and whitespace can be ignored). The test inputs' length can be 100000 ...
9votes
4answers
3kviews
"What is the maximum that Player 1 can win?"
This is a question that I encountered in one of the competitive coding tests. The question goes as follows: A 2-player game is being played. There is a single pile of stones. Every stone has an ...
3votes
2answers
590views
Find the longest sub string of a word after concatenation of given words array
An Array of N words is given. Each word consists of small letters ('a'-'z'). Our goal is to concatenate the words in such a way as to obtain a single word with longest possible substring composed of ...
2votes
2answers
6kviews
Find the minimum number of coin change
Description: You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that ...
1vote
1answer
499views
Reinterpreting a string, treating < as a backspace character
I've come up with a solution to this coding challenge using recursion. In summary, the input is a string where the < symbol represents a backspace (up to 1 ...
1vote
1answer
126views
Count all possible attendance records with length n, which will be regarded as rewardable
Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after \$\mod 10^9 + 7\$. ...
10votes
2answers
449views
You need to diversify your strings
Challenge: Write a program which prints all the permutations of a string in alphabetical order. Specifications: Your program should accept a file as its first argument. The file contains input ...
5votes
3answers
5kviews
Using recursion to count substrings (with exceptions to the rule) in Java
I am going through the CodingBat exercises for Java. Here is the one I have just finished: Given a string, compute recursively the number of times lowercase hi ...
10votes
1answer
2kviews
Arranging 8 queens on an 8x8 board
Print all the ways of arranging eight queens on an 8x8 board. Rules: Queens should not share the same row, column, of any diagonal. Any comment on my solution? I didn't write unit tests but I ...
2votes
2answers
3kviews
Given a digit sequence, print the possible decodings of the given digit sequence
Examples: 12 gives: 'AB' and 'L' and 123 gives 'ABC', 'LC' and 'AW' Here is my attempt: ...
7votes
1answer
526views
An Army of Ones
I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it? Challenge: ...
5votes
4answers
5kviews
Digital root recursive function
Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following? This is also my first time using JUnit, I'd ...
10votes
1answer
4kviews
Project Euler #14 -- longest Collatz sequence
I was reading this question and realized that I didn't know Python well enough to critique the algorithm. So I wrote a Java solution instead, which is inappropriate for that question. Since there's ...
5votes
1answer
2kviews
Finding if there is a subset that sums to a target value from an array of integers
I came across this problem. Problem Statement: Given an array of ints, is it possible to choose a group of some of the ...