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.

Filter by
Sorted by
Tagged with
4 votes
3 answers
181 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 ...
Pankaj Kumar's user avatar
4 votes
1 answer
116 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 ...
Titan's user avatar
  • 41
1 vote
1 answer
65 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 ...
JimmyHu's user avatar
  • 4,708
3 votes
1 answer
75 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 ...
level42's user avatar
  • 131
3 votes
1 answer
35 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 ...
Tanaka Saito's user avatar
0 votes
1 answer
41 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 ...
Aaron Goldsmith's user avatar
1 vote
1 answer
96 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 ...
andrewb's user avatar
  • 113
3 votes
1 answer
90 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 ...
Joel's user avatar
  • 133
2 votes
3 answers
96 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 ...
KcFnMi's user avatar
  • 119
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 ...
Wow1345's user avatar
  • 121
2 votes
2 answers
265 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 ...
eminbihh's user avatar
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 ...
Wow1345's user avatar
  • 121
2 votes
1 answer
54 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 ...
Vladistone's user avatar
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 ...
Luca Natale's user avatar
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 ...
XMehdi01's user avatar
  • 459
1 vote
3 answers
105 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 ...
Tobias Grothe's user avatar
2 votes
2 answers
293 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 ...
Nate Anderson's user avatar
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 ...
low-altitude's user avatar
2 votes
1 answer
71 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 ...
Preatorius's user avatar
6 votes
3 answers
639 views

Redefining queue with different front and rear

...
Sai_krishna's user avatar
1 vote
1 answer
89 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 ...
Tobias Grothe's user avatar
2 votes
2 answers
67 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? ...
Alekam's user avatar
  • 21
3 votes
2 answers
194 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: ...
Bryan C's user avatar
  • 31
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 ...
Oersted's user avatar
  • 299
1 vote
1 answer
46 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 ...
Oersted's user avatar
  • 299
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, <...
Oersted's user avatar
  • 299
-1 votes
0 answers
47 views

Finding the pivot point in a rotated array which has been shifted from kth element

I'm trying to solve the following problem: Joker has a deck of n cards, each with a value written on it. The cards are arranged in ascending order from top to bottom. Joker's master performs a hidden ...
driver's user avatar
  • 210
4 votes
2 answers
447 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 ...
Oersted's user avatar
  • 299
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 ...
Yass's user avatar
  • 21
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 ...
schuelermine's user avatar
3 votes
2 answers
108 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 ...
Soner from The Ottoman Empire's user avatar
1 vote
0 answers
104 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 ...
ProgrammingTenants's user avatar
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: ...
Jarne Vercruysse's user avatar
-2 votes
2 answers
221 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: ...
HeapUnderStop's user avatar
2 votes
1 answer
118 views

Recursive Factorial Calculation in JavaScript

...
XMehdi01's user avatar
  • 459
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. ...
Adám's user avatar
  • 656
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: ...
Amal Krishnan's user avatar
3 votes
0 answers
53 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: ...
SM1312's user avatar
  • 131
4 votes
3 answers
595 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 ...
XMehdi01's user avatar
  • 459
1 vote
1 answer
51 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 ...
XMehdi01's user avatar
  • 459
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 ...
Tyler Schuster's user avatar
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: <...
mascai's user avatar
  • 379
1 vote
1 answer
166 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? ...
Ill Magnus's user avatar
5 votes
2 answers
132 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 ...
Leedo's user avatar
  • 275
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 ...
Looser User's user avatar
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 ...
machine_1's user avatar
  • 581
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 ...
Marc's user avatar
  • 153
5 votes
2 answers
313 views

PHP Fisher-Yates shuffle with random_int

The PHP manual states that the regular shuffle() function isn't cryptographically secure, but that random_int() is. I thought, ...
James G.'s user avatar
5 votes
1 answer
795 views

Dynamic array type using void pointers C

I made my own dynamic array type using void pointers. I'd like to know what you think of my implementation. void pointers are nice but I fear they may be inefficient. The compiler cannot tell what ...
Lead Vaxeral's user avatar
8 votes
4 answers
448 views

Array List C implementation

I want to show you my implementation of the array list in C. Is there something I can improve or fix? Header ...
whiteman808's user avatar

1
2 3 4 5
43