This code takes the no. of nodes in a graph and creates the graph with the number of nodes and then the user has to input the one-way edges between two vertices.(The formed Graph is a Directed Acyclic Graph or DAG). The graph is then sorted by the topological sorting function topoSort The problem is in the topoSortRE method which
Tag: algorithm
Problem in “between two set” hackerrank problem
Problem:You will be given two arrays of integers and asked to determine all integers that satisfy the following two conditions: The elements of the first array are all factors of the integer being considered The integer being considered is a factor of all elements of the second array These numbers are referred to as being between the two arrays. You
Sorting based on order mentioned in a static map using java
How to sort a list of strings based on order mentioned in static map having item of list as key. List={“AU”,”I”,”U”, “O”, “A1”} Need to sort the above list of string using the below map which has …
Change node values to their heights in a binary tree
My task is to change the values of nodes to their heights in a binary tree. By the condition of the task, you need to change all the values in 1 pass of the tree, but you can violate this condition …
Is it possible to decrement counter within a condition?
i am trying to detect a jokerStraightFlush when analysing a poker hand. I need to add a feature where this hand works 8S JK 6S JK 4S. The JK are jokers. I am using the exact same code logic as https://www.codeproject.com/Articles/38821/Make-a-poker-hand-evalutator-in-Java. cardsTable represents the distribution of the Card ranks present in the hand. Each element of this array represents the
Make a sequence an increasing sequence by adding a number multiple times
I have an array of numbers, now I want to make this as increasing sequence by adding a fixed number b. I want to find how many times the fixed number b is added to make my array as increasing sequence….
Can’t access my linked list methods and can’t iterate trough it
So im following along this playlist about data structures and in this video to conclude the linked list part, the professor explain we need an inner class called IteratorHelper. Video: https://www.youtube.com/watch?v=bx0ebSGUKto&list=PLpPXw4zFa0uKKhaSz87IowJnOTzh9tiBk&index=21 This is the code in my github with the linked list implementation and the main class called tester: https://github.com/Ghevi/Algos-DataStructures/tree/master/src/com/ghevi/ads/linkedlists The problem is that the tester class can’t compile. If
Remove last occurrence of a specific integer from an array
For some reason, my solution is not complete. I got 80/100 from hidden spec tests. What’s wrong with my solution? There is probably a certain use case that I’m not thinking of. How would space/time complexity change using an ArrayList instead of an array? Is there a better way to tackle this problem? My current solution handles: an empty input
How to check if string has repeating pattern?
I was recently asked this in an interview question: Given a input string check if it has repeating pattern and return true or false. For example: “abbaabbaabbaabba” is a repeating pattern of “abba” How can we solve it using regex and also without regex? I am interested in both the approaches with regex and without regex. Answer Without regex, you
Concatenate the words to obtain a single word with the longest possible substring composed of a single letter
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 say as to obtain a single word with the longest possible sub-string …