Category "algorithm"

Which data structure can act like a circular queue?

The picture above has 25 action points such that: Each of the four corners of each of the three layers is an action point. The midsection of each of the four s

Big(O) time complexity unable to find

What is time complexity of following code : int count = 0; for (int i = N; i > 0; i /= 2) { for (int j = 0; j < i; j++) { count += 1;

A problem was caused by an array that was not initialized

I am trying to solve a execise, which amis to find the Last Digit of a Large Fibonacci Number, and I try to search for others' solution, and I find one here: h

How to get original array from random shuffle of an array

I was asked in an interview today below question. I gave O(nlgn) solution but I was asked to give O(n) solution. I could not come up with O(n) solution. Can you

Minimum moves to transform a list so that each element equals its own frequency

Given a sorted array like [1,2,4,4,4]. Each element in the array should occur exactly same number of times as element. For Example 1 should occur 1 time, 2 shou

How to convert an XML structured-like object to a JSON string in Java?

So I have an XML structured object (Java) and need some help to convert it to a JSON string without using any library and in an iterative way. E.g <root>

Adding all elements of an array except the element at index with O(n) complexity

This is what i came thru a problem in some coding test. problem statement was like that we have to add all the elements of an array except the element at the i

How to I make my AI algorithm play 9 board tic-tac-toe?

In order to make it easy for others to help me I have put all the codes here https://pastebin.com/WENzM41k it will starts as 2 agents compete each other. I'm t

How do I check if an array includes a value in JavaScript?

What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) {

Finding performance feasibility using array strings

Here is the requirement details: time = ["09-13", "12-14"] getResult(time) = false The first performance runs from 9 a.m. to 1 p.m. and the second one starts

Finding Arithmetic Mean of Subarrays Efficiently in an Array

I am trying to find number of ways o calculate arithmetic mean of a subarray of an array. It boils down to this; given an array X and an integer S, how many con

How to find Z highest subset Sums from the array of N elements

I have an array of numbers, now I want to find all possible subset sums and get the top z elements in it. Example: Input : arr[] = {2, 4, 5}, z = 3 SubsetSums

Minimum number of swaps required to make a binary string palindrome

Give a binary string consisting of 0's and 1's only. E.g., 0100101. We are allowed to pick any two indexes and swap them. We have to return the minimum number o

Get PDF images in an array using PDFIUM to edit them

I am trying to write down a method to get all PDF images from a FPDF_DOCUMENT object to perform actions on them and return back theFPDF_DOCUMENT with the images

Solving a Chain Link Python Puzzle:

I am not sure where to start with the following python puzzle. "You are holding a link of a chain. Implement a method longerSide to find which side of the chain

heapify VS build heap

Can you please confirm the meaning of the concept 'heapify', the source I am learning from says that heapify is building a heap from an array (from scratch) Thi

Find the max value of the same length nails after hammered

I'm trying to solve this problem: Given an array of positive integers, and an integer Y, you are allowed to replace at most Y array-elements with lesser val

Problems with using a rough greyscale algorithm?

So I'm designing a few programs for editing photos in python using PIL and one of them was converting an image to greyscale (I'm avoiding the use of any functio

Swapping elements between A and B to get sums equality

We have two arrays of equal length, A and B. also, for every i: 0 <= a_i, b_i <= m for some 1<=m<= 1000000. We want to check if a single swap bet

Grouping/Clustering Rectangles

I have a list of shapes (list of points) e.g. rectangles which I want to group/cluster together. This is what I have: And this is what I want to achieve. How