I want to print all number combinations that are in ascending order. The output should go like: 012, 013, 014, …, 789 for n = 3. I tried to solve it using recursion, however I’m having the StackOverflowError. So it means it never reaches the result. Here is my code so far: Answer There are these issues in your code:
Tag: algorithm
Correct Use Of Factory Pattern?
I have been doing research on the factory design pattern and was wondering if the below example, while not “textbook” is technically a correct use of it. Is there another design pattern that may fit the situation better? Answer IMO: Looks like the given code example actually implemented the Factory Method pattern with using the Method Object solution https://refactoring.guru/replace-method-with-method-object. Because
Count the Characters in a String Recursively & treat “eu” as a Single Character
I am new to Java, and I’m trying to figure out how to count Characters in the given string and threat a combination of two characters “eu” as a single character, and still count all other characters as one character. And I want to do that using recursion. Consider the following example. Input: Desired output: Current output: I’ve been trying
Newest version Postman creating different signature for AWS access compared to my java algorithm
So I’ve created the java algorithm for AWS signature creation, following the guidelines of AWS >https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html The algorithm is available on my github >https://github.com/marcodag/aws_signature_creation/blob/main/SignatureCreation.java These are the steps that I take: retrieve secret key, access key and token from AWS account create call on Postman (for Linux) v8.12.5, by using AWS Signature auth the call goes OK. I retrieve the
Fill the Third Array by adding the elements of the First and Second Arrays
I want to generate an array which content would represent a Cartesian product of the two given string-arrays. In other words, I need to concatenate each String from the first array arr1 with every String from the second array arr2. Here is my code: Current Output: Desired Output: How can I fix it? Answer You don’t need the very first
The longest Substring without Repeating Characters
I’m starting out on LeetCode, and am currently working on the problem Longest Substring Without Repeating Characters. Given a string s, find the length of the longest substring without repeating characters. Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. I feel like my approach should work, but for some reason it fails
Optimal way to find manager phone number whose subordinates live in more than one city in a graph
I am trying Find the phone numbers of all managers whose direct report hierarchy live in more than 1 city in O(n) time complexity. Below is my approach which is using with Time Complexity O(M*N) where M is the number of managers and N is the Number of employess. Can someone please help me with O(N) solution for this problem.
Find index in array based on given value
I have a sorted array of numbers with array length as n. For a given item k find index i in the sorted array where elements from index i to n are greater than the given item k. If there is no index present then return -1 This is my program: The time complexity of this approach is O(n), and
Algorithm to get the submultiples of each number in a range
I have this exercise in mind, I keep trying to solve it in Java but I’m not able to create a correct algorithm to get the submultiples of each number in a range, the start and the end of the range is user defined. Besides, the number 1 doesn’t count as a submultiple. For example, in a range between 3
Sort String of Characters Using Hashed Array and Java 8 Streams
I stumble upon this cool sorting algorithm with O(n) time complexity on GeeksforGeeks – Sort string of characters and I was trying to refactor the code to use Java Streams on the nested for loops instead and collect the result in a string variable but I can’t seem to wrap my head around it. Here’s the original code: Answer Try