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 votes
0 answers
85 views

How to explain the logic of the pairing of the 2018 FIDE World Chess Candidates Tournament? [closed]

Update-2 This is indeed a standard ‘circle’ schedule with players renumbered from 1:7 to ‘2’, ‘8’, ‘4’, ‘5’, ‘3’, ‘6’, ‘1’. Rounds 6 and 7 are swapped. To reproduce: # ---------------------------------...
clp's user avatar
  • 1,460
2 votes
2 answers
82 views

Finding the subarray 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 ...
Lesserrafim's user avatar
1 vote
1 answer
66 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 ...
Damyan Myashkov's user avatar
1 vote
1 answer
179 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,...
Ishigami's user avatar
  • 239
0 votes
0 answers
50 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 ...
BorKus's user avatar
  • 9
1 vote
2 answers
79 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 ...
Patric's user avatar
  • 11
-1 votes
2 answers
96 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 ...
bugdebug's user avatar
-1 votes
0 answers
17 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, פונקציית ...
Yasmeen Phone's user avatar
0 votes
3 answers
70 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 ...
Ahmed Salah's user avatar
-2 votes
3 answers
103 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 ...
Prince Kumar Prajapati's user avatar
1 vote
2 answers
300 views

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 ...
Jony's user avatar
  • 37
1 vote
0 answers
29 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 (...
Vinh Nguyễn's user avatar
2 votes
1 answer
34 views

Why do you exclude negative numbers from a max path sum algorithm

Here is a correct max path sum algorithm export function maxPathSum(tree: BinaryTree): number { let currMax = -Infinity; const helper = (node: BinaryTree | null): number => { if (!node) ...
J Seabolt's user avatar
  • 2,878
1 vote
2 answers
68 views

How to break multiple try catch blocks in powershell

I have a class with +- 25 API functions for which I want to write a test-script. I test my API-functions before and after a software upgrade so that I'm sure everything remains working. However, I ...
user3127554's user avatar
-8 votes
1 answer
62 views

I have a task to count the number of times I've played music from favorite artists and I need to rank it from most played to least played [closed]

What is the difference between the first function and the second function if they do the same task and what is faster? Note that the first function of GPT4 chat def selectionSort(arr): ""...
Yousef Almosawa's user avatar

15 30 50 per page