Currently I have a list of Strings that represent a date in a yyyyMM format, something like this: 202008 202009 202010 I need to create x number of entries in this list with each entry increasing …
Tag: algorithm
breaking down words in different ways in java
I want to create words that come with a string in different ways as follows. I’m not sure how best to do this input: Paul Thomas Anderson output: Paul Thomas Anderson, P Thomas Anderson, T Anderson, …
How would the weighted quick-union Algorithm be implemented?
I’m currently enrolled in the Princeton Algorithms course (Part 1) and it talks about an improvement to the quick-union algorithm by maintaining an extra array sz[i] to count the number of objects in the tree rooted i, but it doesn’t show how to do that. Where and how is that counter supposed to be implemented? I’ve tried doing it in
Is it possible to use 2 Data Type in an Custom ADT(Sorted Linked List)?
I am trying to do a Leaderboard for a game by using a Sorted Linked List. I was able to do so by sorting the point in descending order which mean higher point to lower point. Moreover, I will also …
How to sort two arrays with one being sorted based on the sorting of the other?
So I have encountered this problem a lot of times. Let me explain. Say I have these two arrays: A1={1,2,3,4,5,6,7,8,9,10}; and A2={1,2,3,0,2,1,1,0,0,0};. What I require is this: When I sort A2, whatever swapping and shifting of elements takes place in A2, the same should take place in A1 as well. Basically I am trying to create a Map using two
Ambiguity in a CodeForces Problem – usage of HashSet Vs LinkedHashSet
I was solving a Codeforces problem yesterday. The problem’s URL is this I will just explain the question in short below. Given a binary string, divide it into a minimum number of subsequences in such …
How do I recursively count up to less than n [closed]
I am struggling with the problem of having applications of loops and arrays. I have a variable “n” which represents the limit of the loop, i.e. if n = 3, the array would look like: arr[1,2,3,…
Karatsuba Algorithm without BigInteger in Java, unexpected behaviour while recursion
So I want to run Karatsuba Algorithm without using class BigInteger in Java, so upon following the pseudo-code and this question, I came with the following code Now, the problem with this is that it’s producing the wrong answer, 1234*5678 is giving 11686652, which should’ve been 7006652. As a beginner to Java and algorithms, I am unable to pinpoint the
Split a list into n sublists in all possible ways
I want to split a list into a given number n sublists in all possible ways in Java. For example [1, 2, 3, 4] where n = 3 would include the following lists (but would not be a complete solution – complete would require much more space): etc I adapted a solution from another similar question (Split a list into
Add new edge to Graph and check if total weight is reduced
I’m new to Graphs and I’m trying to solve this problem in Java: Given a Graph with N nodes and N-1 weighted bidirectional edges, the algorithm must respond YES if a new edge ‘q’ allows to reduce the overall weight of the graph, NO otherwise. The edge ‘q’ satisfies this condition if there is an edge ‘e’ such that it