So I got this question in my assignment and I did almost all other than the last part, the code works fine. The question I got is mentioned below. Write a program to generate any number of random integers in 0 to 100 range. Your program should get the size as a parameter and return the numbers as an array.
Tag: algorithm
Making a island large leetcode – spotting mistake Java
I am working on LeetCode problem 827. Making A Large Island: You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. Example 1: Input: grid =
A* pathfinding algorithm is being semi-greedy
So I have been trying to implement the A* pathfinding algorithm for a 2D tilemap in Java from this video: https://www.youtube.com/watch?v=-L-WgKMFuhE. I tried following the pseudocode and not enough details, I felt, were not explained greatly, especially the idea of the G cost. So, I decided to go into the actual code the video creator wrote and used a lot
How to get all one and two letter combinations in order from a word?
For example, there is a line It is necessary to get all possible combinations, such as: p-r-o-g-r-a-m p-r-o-g-r-am p-r-o-g-ra-m pr-og-r-am and so on. How do I do this in java? Or at least tell me a general algorithm (with an example)? It is not a problem to break the deadline, at least one character at a time, at least two,
Maximum number of tasks to be performed
I’m stucking in a problem. I know dp can be applied here, but not getting it. Consider a part of the positive number line starting at 0 and ending at 10^9. You start at 0 and there are N tasks can be performed. The ith task is at l[i] and requires t[i] time to be performed. To perform ith task,
Simple text maze solver that starts from middle point doesn’t end when finding first exit
I searched for a problem close to mine but every maze has some starting or finishing points or starts from the edge of the maze. I want to find the first exit possible starting from the middle of teh maze and print the maze with the route to the exit. For example I have maze like this: And we start
How do I count numbers that contain one digit, but not another?
I recently came across an interview question which although had an immediately obvious solution, I struggled to find a more efficient one. The actual question involved counting numbers from a to b (up to 2^64) which satisfied having either the digit 6 or 8, but not both. They called it a ‘lucky number’. So for example: The obvious thought was
Something wrong with BigInteger
when i test this function with base16 :F0F0F0F0F0F0F0, it return right result = 67818912035696880 BUT when i test with base16: F0F0F0F0F0F0F0F0, it returns wrong result: 17361641481138401580 which right result must be 17361641481138401520 please help me! Answer Math.pow delivers a double, 8 bytes. So from some huge double value, it becomes imprecise in the less significant digits. You could have used
Need Help converting JavaObject To Json in Generic Pattern
I wrote a Generic method which works fine converting any Json object to Generic Object. But has an issue while converting the Generic Object type to JSON format with the below code format. Would someone help me or guide me with related code.. I am not sure how to retain an Object from Generic class type as the method doesn’t
calculate the percentage increase or decrease in a list of values in java
i’m trying to build an data structures and algorithms program using java. and i wanna ask if anyone know How do i calculate the percentage increase or decrease in a array. i try this code–but apparently its not the correct way Run-> Percentage change is = Infinity % Answer Here you’re dealing with the numbers, which could go in the