I’m trying to solve the problem of “count ways to reach the nth step in a staircase” with recursion. When given a number of stairs to climb, I have to calculate the number of ways to climb taking either 1 or 2 steps at a time. For example, if there are 4 stairs, we would return 5 since we would
Tag: recursion
Count occurrences of a given integer in an array using recursion
Without using a loop, I’m trying to count the number of times a given integer is in an array using recursion. I keep getting a StackOverflow error and I can’t figure out why. } Answer If you can use only two parameters, then try:
why is there a stack overflow error in a recursive solution to finding the factorials of a number?
I’m solving LeetCode #172: Given an integer n, return the number of trailing zeroes in n! Constraints: 0 <= n <= 104 My code finds the answer of n! first and then counts the number of trailing zeroes. However, running the code throws a stack overflow exception, and I can’t for the life of me figure out why. This is
Can I use a lambda function like this?
I want to try to use lambda functions (which I do not understand well) so I can learn more about them. I have an assignment on trees that has us making a family tree class. children is a set of all of the children nodes to this node. Also as a side question, does this usage of AtomicInteger work similarly
Flat tree of objects while keeping father and child
I have a class Employee which has a tree structure with property team Using Java lambdas I need to flat this tree into same level list while converting Employee class into the following ConvertedEmployee while storing names in dedicated lead and subordinates properties. So ConvertedEmployee is in some sense a node which keeps parent and children. And I need to
Building a Recursive Data Structure with Spring WebFlux
I have a REST API that is built with the Spring WebFlux framework, and I have an endpoint which returns a Flux<ChannelResponse>, where ChannelResponse is a tree-structured object, as shown below: Now, I don’t have much experience with the reactive programming paradigm, but this is how I would implement such an endpoint with synchronous logic, such that each top-level channel
Need help understanding basic recursion problem
I have just started practicing with recursion I have this very simple practice program problem. There are bunnies standing in a line, numbered 1,2,3… The odd bunnies (1,2,3..) have normal 2 ears. The even bunnies (2,4,6…) have 3 ears, because they each have a raised foot. Recursively return the number of ears in the bunny line. I have the solution.
Finding a the “sub-path” in a hierarchical system, Java
I have this Hierarchical file system that is built like so: Given a path (not necessarily the complete path) for example for this system: a path be given like so: I am trying to make a function return the specified File if there exists a path where the given path is part of it, for example if it finds the
Recursion with bitwise operators
I have the following method in java that simplify Nor expressions using recursion: Now, when I want to simplify the expression (T ↓ y) ↓ y , it ouputs F ↓ y instead of ~(y). How I need to change the recursion to output the right simplified expression? Answer Your case isn’t covered, so you get the default, all the
Index of first distinct character between two strings using a recursive method
I need to find the index of the first distinct character between two strings using a recursive method. Examples with expected outputs: rFirstDistinctPlace(“Little parcels”, “Little pretzels”) -> 8 rFirstDistinctPlace(“Gold shadow”, “gold shadow”) -> 0 rFirstDistinctPlace(“gold”, “golda”) -> 4 rFirstDistinctPlace(“gold”,”gold”) -> -1 Note: I can’t use the .equals() function The thing I’m struggling with is that I need to return -1