Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [algorithm]

An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

1 vote
3 answers
78 views

Fast integer sqrt using Math.Sqrt

I'm trying to calculate the square root of integer values. It doesn't need to be very accurate, but it should be fast and deterministic across platforms. I'm using this for a RTS game with lockstep ...
0 votes
0 answers
6 views

Traverse a graph with multiple stops from a starting point? [duplicate]

I have an undirected weighted graph I need to traverse from X node to a list of nodes. The list is unordered by default, meaning that the order of which nodes are traversed is not important. What's ...
0 votes
0 answers
13 views

The model(DecisionTreeClassifier) gives wrong results

I'm taking a machine learning course with an assignment to implement a fit method for DecisionTreeClassifier. Here are the links for more information: https://stepik.org/lesson/333977/step/8?auth=...
-7 votes
1 answer
50 views

WiggleSort: giving wrong output? [closed]

I am trying to solve LeetCode problem 324. Wiggle Sort II: Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... You may assume the input array always ...
7 votes
5 answers
6k views

Calculating the Bounding Rectangle at an Angle of a Polygon

I have the need to determine the bounding rectangle for a polygon at an arbitrary angle. This picture illustrates what I need to do: alt text http://kevlar.net/RotatedBoundingRectangle.png The pink ...
0 votes
1 answer
62 views

How to store row-position in a database?

I am looking to emulate a feature in Excel/Google Sheets where there is a table of data, but someone may move a row up or down. Here is an example of the interaction: My first thought as to how to ...
3 votes
3 answers
5k views

How do I make my implementation of greedy set cover faster?

I came up with the following implementation for the Greedy Set Cover after much discussion regarding my original question here. From the help I received, I encoded the problem into a "Greedy Set Cover"...
0 votes
0 answers
44 views

How can I estimate the difference in performance of a HashMap lookup vs List iteration in Kotlin?

I am working on an application that needs to map pdf documents to corresponding json data files (see: Kotlin data structure for efficient lookup of nested data for more details). In trying to ...
0 votes
2 answers
89 views

Finding if strings can be anagrams

I have String s1 and String s2. I want to check whether it is possible to make s1 an anagram of s2 by removing a single character zero or more times from s1, and removing a single character zero or ...
-1 votes
0 answers
41 views

What is the time complexity of list1==list2 operation in Python? [duplicate]

It was my understanding that a condition equating operation would always be O(1) as we are simply checking if LHS is same as RHS. But this scenario got me thinking. if list1 == list2: print("Hi&...
-8 votes
0 answers
42 views

Did Everyone know about Netflix game downloading algorithm on IOS? [closed]

We try to build a Games centre App that allow user can download game from our app. but in IOS we can't download directly like Andiron so try the other way like following Netflix game downloading flow ...
0 votes
2 answers
55 views

How is my algorithm for stock span problem incorrect?

The question : The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stocks price for all n days. The span Si of ...
0 votes
1 answer
41 views

Kotlin data structure for efficient lookup of nested data

I am currently working on an application that needs to create a mapping between document pdfs and corresponding JSON data files. The files are coming from a third party so I have no control over their ...
67 votes
17 answers
139k views

Efficiently getting all divisors of a given number

According to this post, we can get all divisors of a number through the following codes. for (int i = 1; i <= num; ++i){ if (num % i == 0) cout << i << endl; } For example,...
-1 votes
0 answers
22 views

What should I focus while learning DSA? [closed]

So basically I am learning DSA for the first time and I dont want to overlearn or learn things that aren't neccessary. Can anyone tell me what I should focus on? DSA learning I am learning quick union ...

15 30 50 per page
1
2 3 4 5
8075