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.
algorithm
121,044
questions
0
votes
0
answers
3
views
Should we really condition the lastIndex based on whenever array.length is odd or even in isMajority challenge?
Here are the details of the problem:
Given an array arr of N elements, A majority element in an array arr of size N is an element that appears more than N/2 times in the array. The task is to write a ...
-5
votes
0
answers
15
views
ski rental problem with change in purchase price every day [closed]
So im struggling to solve this problem:
Consider a variation of the ski rental problem where the purchase price decreases each day by half the rental price. Assume the rental price is 1 per day.
The ...
1
vote
1
answer
28
views
Finding the subsequence with the least median given a size K and an array of length N
I have been struggling the past month with this problem that was given to us on our course while I was upsolving it. The task is to find the window of size K with the least median in an array of ...
1
vote
1
answer
50
views
Why is this algorithm O(n*n) - Manacher algorithm implementation?
So I was recently doing leetcode problem number 5 - longest palindromic substring, which outputs the longest palindromic substring out of a string. I have studied Manacher's algorithm but I didn't ...
-4
votes
0
answers
21
views
Association Rule Mining support count where there are duplicated items [closed]
When I learned about Association Rule Mining, the example was similar to https://www.geeksforgeeks.org/frequent-item-set-in-data-set-association-rule-mining/ and Frequent Itemsets & Association ...
-1
votes
0
answers
44
views
Swift: Complex matching algorithm needed
I have a problem implementing an algorithm to match invoices with transactions. So far the matching works quite well but from the code with the comment:
// Search for a transaction that can cover ...
0
votes
0
answers
77
views
Permutation summation in Pandas dataframe growing super exponentially
I have a pandas dataframe that looks like
import pandas as pd
data = {
"Race_ID": [2,2,2,2,2,5,5,5,5,5,5],
"Student_ID": [1,2,3,4,5,9,10,2,3,6,5],
"theta": [8,9,2,...
0
votes
0
answers
43
views
Design a Data structure ~(simple rate limiter) [closed]
I'm studying DSA for my interviews && university exams and kinda stuck right now.
There is a problem statement: given n(limit of request) and m(window time), design a data structure that ...
1
vote
2
answers
68
views
How to sort an array by only being able to swap an element with another element two positions ahead (i+2)?
I have an array of integers that I need to sort. However, the only operation allowed is to swap an element at index i with the element at index i+2. This means traditional sorting algorithms like ...
-1
votes
2
answers
62
views
Flip consecutive zeroes to ones in k operations to have maximum number of ones, find the maximum number of ones
You are given a binary string made of 0 and 1, and a value k which represents number of operations. You can flip consecutive 0s in each operation to 1s. Find the maximum number of 1s after k ...
-1
votes
0
answers
16
views
how to find the Minimum Spanning Tree on graph like that? [closed]
enter image description here
i think that this quastion have a liniar complexity solution ; i will addd the algorithm of procedure Prim(G, w):
input: גרף G עם קבוצת צמתים V וקבוצת קשתות E, פונקציית ...
0
votes
3
answers
56
views
difficulty to understand the code, and maybe the concept itself (recursion problem)
this code below is from Grokking Algorithms book that is an exercise for the functional programming/recursion and an application for the D&C concept. the function finds the maximum number in a ...
-1
votes
3
answers
97
views
How can I print this pattern [closed]
Problem statement:
You are given an integer n, representing the side length of a rhombus. Your task is to write a program to print the pattern of the sides and diagonals of the rhombus.
INPUT
The ...
0
votes
0
answers
118
views
+100
How to fix color bar in canvas?
I have JavaScript code that draws vertical bars and changes their color based on the average music frequency. I tried to change the color of each bar to match the color of the previous bar, but I got ...
1
vote
0
answers
27
views
Calculate node value based on its surrounding cells [closed]
I have a 2D float array of width * height elements and I want to generate a mesh using it as a heightmap. The texture I've generated from the array was also width * height, so the mesh should have (...