Questions tagged [array]
An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.
2,122
questions
2
votes
1
answer
155
views
Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms
I was doing the Hackerrank "New Year chaos" problem. Here is the description:
It is New Year's Day and people are in line for the Wonderland
rollercoaster ride. Each person wears a sticker ...
2
votes
1
answer
69
views
Research program for examining array list arithmetic contractions
Introduction
Suppose we have a dynamic table \$T\$. Let \$\vert T \vert\$ denote the number of elements currently stored in \$T\$, and \$\vert \vert T \vert \vert\$ denote the capacity of \$T\$. Also, ...
6
votes
5
answers
455
views
Fill missing data in between available data with default value
My raw data has values on some random times:
const rawData = [
{hour: 3, value: 3} ,
{hour: 5, value: 9} ,
{hour: 10, value: 5} ,
] as const
I would like to ...
-2
votes
1
answer
57
views
I wrote a O(log N) code for largest element in an array today but is this an already existing way to find max element in an array? [closed]
Largest element in an array's most optimal approach. The code I have written has passed all test cases in https://www.naukri.com/code360/problems/largest-element-in-the-array-largest-element-in-the-...
4
votes
3
answers
240
views
Given two sparse vectors, compute their dot product
Problem Statement:
Given two sparse vectors, compute their dot product.
Implement class SparseVector:
SparseVector(nums) Initializes the object with the vector nums
dotProduct(vec) Compute the dot ...
4
votes
1
answer
121
views
Finding the earliest time we can schedule
We have a list of \$j \in \{1,\ldots,N\}\$ jobs with a processing time \$p_j\$ and a demand \$d_j\$ between 0 and 1. These are real numbers. Jobs require the fixed demand over the entirety of their ...
1
vote
1
answer
76
views
Find Method Implementation for Multidimensional Array in C#
I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post.
The experimental implementation
The ...
3
votes
1
answer
87
views
Creating an array (temporary table) in SQL and iterating through each row within this table to preform a check on the data in each row
The SQL Server version I am using is SQL Server 2008.
I've got an SQL query/script I've written which is to help simplify some things while our API is being rebuilt.
Essentially, this script allows ...
3
votes
1
answer
44
views
Comparing a set of parameters contained in two separate strings in Powershell
I have a situation where I need to compare two strings with each other in a foreach loop that potentially run over millions of rows of data. The two strings will always contain between 1 and 12 ...
0
votes
1
answer
42
views
Updating class method to use data from new weather API endpoint while keeping same return value object structure as with old endpoint
I needed to update a class in Node.js that parses the response from a new weather API endpoint but still preserves the same object structure and key values from having been using the old weather API ...
1
vote
1
answer
97
views
"stray" point correction in 2D array
I have a code which does the following:
For each value v in a 2D array, look at neighboring positions - how far to look is specified by distThreshold. If the count ...
3
votes
1
answer
109
views
Writing a multidimensional array view for contiguous arrays in C++20
When creating little games or other programs I often need multidimensional arrays. Usually I just do the simple std::vector<std::vector<T>> thing for ...
2
votes
3
answers
106
views
A dynamic array with an iterator compatible with std::sort
I wrote a Vector (dynamic array) class with an iterator usable with std::sort() . It seems to pass my tests.
I wondering about the issues one can spot on this ...
6
votes
4
answers
1k
views
Automate character search in C
THE TASK
We are dealing with a string of symbols and need quick responses to queries of the following types:
What is the position of the k-th occurrence of symbol X in the string?
Reading from ...
2
votes
2
answers
267
views
Optimizing Subarray Removal: Can the Removal Process be Enhanced for Better Efficiency?
The only requirement is that it has to be done by pointers:
And it returns the amount of removed numbers because of the way of output that is set in the main.
The function, using exclusively pointer ...
6
votes
1
answer
55
views
Chessboard configuartions with no possible capture on the next move
THE TASK:
Given an NxM "chess"board and Q,R,B,K where Q is the number of queens, R the number of rooks, B the number of bishops, and K the number of knights find out how many possible ...
2
votes
1
answer
55
views
How better methods of remaking the code by array without changing its functionality, and performance but reducing amount by ~10 times
Can anybody help me with examples of code?
How is the approach to optimize code relative to my example with using "switch case" to "arrays"? Without changing its functionality, but ...
2
votes
1
answer
57
views
JS animated string builder
Today, I tried to write a simple function that would display the characters of my string one by one by iterating over a string containing the letters of the alphabet and showing the steps on the ...
3
votes
4
answers
1k
views
Merging sorted integer arrays (without duplicates)
I have written a Python function called merge_arrays which takes two lists and returns the new list merge without duplicate.
The function works as expected, but my ...
1
vote
3
answers
112
views
Another ATMs cash-out (denomination) algorithm in Java
Related to this question and this answer, I would like to have a second review from you on a modified version.
The problem I tried to solve
Some kind of "Minimum count of numbers required from ...
2
votes
2
answers
302
views
Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values
Here's a code challenge I got. (I could not solve the challenge, I ran out of time. I rephrased the challenge language and I am trying the challenge again for personal growth & computer science ...
4
votes
2
answers
2k
views
Linked list and array list performance comparison in C
After watching Stroustrup's presentation on performance comparison between vectors and linked lists (https://youtu.be/YQs6IC-vgmo?si=9r5wXqnwkmN29xqn), I've decided it would be a good problem to get a ...
2
votes
1
answer
78
views
Implementing an improved merge sort that uses insertion sort, with "levels" - Would this work correctly?
We were asked to improve the merge sort algorithm by introducing insertion sort to the code. We have been tasked with doing this by utilising a "levels" logic. Here is the exact description ...
6
votes
3
answers
639
views
1
vote
1
answer
90
views
Shrink an array of double elements (uniformly)
Is there a way to avoid the first loop in the method shrink? (if and while...)
The utility ...
2
votes
2
answers
69
views
Calculating the sum of all k-sized sub-arrays in an array using sliding window algorithm
I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why?
...
3
votes
2
answers
202
views
Counting duplicate elements in two sorted arrays
I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with:
...
2
votes
0
answers
45
views
Reusable storage for array of objects V4
Here is a thirdfollow up on Reusable storage for array of objects, Reusable storage for array of objects V2 and Reusable storage for array of objects V3, taking into account the provided answers.
The ...
1
vote
1
answer
47
views
Reusable storage for array of objects V3
Here is a second follow up on Reusable storage for array of objects and Reusable storage for array of objects V2, taking into account the provided answers.
The following code should be compliant at ...
3
votes
1
answer
64
views
Reusable storage for array of objects V2
Here is a follow up on Reusable storage for array of objects, taking into account the provided answers.
The following code should be compliant at least with gcc, <...
4
votes
2
answers
476
views
Reusable storage for array of objects
My goal is to have a memory pool non-template class that is used to store arrays of objects.
The same memory pool object must be reusable for a different array (difference size, different type and/or ...
2
votes
0
answers
79
views
Javascript basic search engine recipes
I have made a search engine for recipes. Requirements for this JS Project are as follow:
Create a function called searchRecipes that takes all recipes and an ...
3
votes
3
answers
1k
views
Small code exercise with 3D arrays in C
I wrote a small program that initializes a 3D array in C based on command-line arguments and prints it. I did my best to avoid undefined behavior and memory errors. I wrote comments as if I had an ...
3
votes
2
answers
112
views
Quickselect algorithm implementation and its time-complexity
I wrote this code to find kth smallest element in the array by renowned algorithm quickselect. Here is the link where you can see the working code.
What points are there to be improved? Could you ...
1
vote
0
answers
115
views
Performant 2D Grid Cluster Finder Algorithm
I would like to vastly improve the speed of the second part of this algorithm to find clusters of points on a 2D grid.
Each point is represented by a Region on the ...
5
votes
4
answers
2k
views
Automate the boring stuff with python - Character picture grid
Character Picture Grid
Say you have a list of lists where each value in the inner lists is a one-character string, like this:
...
-2
votes
2
answers
224
views
Count the number of mismatches between two arrays [closed]
This function may compute the amount of unequal elements of two char-arrays of the length n:
...
2
votes
1
answer
124
views
3
votes
1
answer
73
views
Dyalog APL dyadic operator deriving ambivalent function to pair two function results
I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. ...
0
votes
1
answer
56
views
The Matrix Winds In
The Problem: Given an N by M Matrix, Create an Anti-Clockwise Traversal Path that winds in all the way into the Matrix
Example: The Matrix is 9 by 5
Output:
...
3
votes
0
answers
56
views
extracting values from an array of nested objects without duplicates
I have my solution for the below usecase but I would like to know whether is any other effective solution for the same.
My Data:
...
4
votes
3
answers
718
views
Determine whether two arrays have the same elements with the same multiplicities
I have written a Python function called comp that checks whether two given arrays have the same elements, with the same multiplicities. The multiplicity of a member ...
1
vote
1
answer
52
views
Optimizing the Dig Pow function
I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
2
votes
2
answers
65
views
Given a sorted list of integers, find the highest count of elements between an indeterminate but fixed size range
I'm trying to optimize a function that takes a sorted list of integers and tells me what is the maximum number of elements in the list between any definite size range. To be clear, the range itself ...
6
votes
3
answers
1k
views
Merge Sorted Array in Rust
I was solving this task https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/
The main idea is to merge two sorted arrays (more details in the site)
Example:
<...
1
vote
1
answer
175
views
swap two different length group of variable in array
The code below swaps two different-length groups of variables of the same array in the same array.
Is there any other method to achieve this that is less heavy or less redundant?
...
5
votes
2
answers
133
views
concatenate values and delete the remaining rows using arrays
the below code used to:
Concatenate the values on a specific column "N" depend on the value of column "A" then delete the remaining rows.
It works, but with range of 30k rows the ...
0
votes
1
answer
31
views
Mangle words to bytearray of lo/hibytes
I would like to refactor the following code snippet adapted from a project I'm involved. It is part of a code to control power outlets via network. The code snippet was written by myself based on the ...
4
votes
3
answers
3k
views
Custom array class in C++
I wrote a custom array class in C++ to suit my personal use case. The main important rule in this project is that no unassigned element is allowed between 2 assigned elements; please review for ...
1
vote
2
answers
47
views
Extend native `Array` instances
I need/want to extend created array instance, to add extra methods that i see as useful.
class.labels.js
...