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,131 questions
2
votes
2
answers
1k
views
Variable length nested list of lists pad shape
Find shape of n-dim array that'd be formed from nested list of lists with variable lengths if we were to pad the lists to same length at each nest level. E.g.
...
5
votes
3
answers
1k
views
FizzBuzz, but with provided start and end of sequence, results stored in array, and a separate function to convert integers to strings
To learn C, I'm doing the traditional FizzBuzz challenge with extra restrictions:
The start and end of sequence is provided by the user
Instead of directly printing the results, the results must be ...
1
vote
1
answer
439
views
Calculate distances between two multi-dimensional arrays in Matlab
In question "Dictionary based non-local mean implementation in Matlab", the Manhattan distance between two three-dimensional structures can be calculated by ...
0
votes
2
answers
533
views
Time complexity of generating Pascal's triangle
This is LeetCode question 118 Pascal's triangle.
Given an integer numRows, return the first numRows of Pascal's triangle.
There is an example.
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1]...
4
votes
2
answers
3k
views
Is there a simpler way to sum the lengths of arrays within an array of arrays in JavaScript?
I primarily work with C#, and when working with an array of arrays, I can sum the length of the sub arrays using Linq:
...
1
vote
2
answers
3k
views
Add Properties from one array of Objects to another array of Objects based on property id
I do have my code running but again I'm wondering if there is a nicer solution since mine seems to be clumsy and I'm wondering if there is a better way like chaining (but I can't work out how to do ...
0
votes
1
answer
200
views
Is it possible to get a better performance using memoization? Array algorithm
I have a working solution for the problem below. I have the feeling that it could be improved using memoization, but I cannot see how to do it.
The problem:
You are given an array arr of N integers. ...
3
votes
1
answer
180
views
Dictionary based non-local mean implementation in Matlab
Given a dictionary including multiple X-Y pairs where X, Y are both three dimensional structure. dictionaryBasedNonlocalMean function returns a ...
2
votes
1
answer
806
views
=PRINTF("{1} - {2}", ... ) in Excel without VBA - LAMBDA functions with variable number of arguments
The TEXTJOIN function has a really nice interface:
=TEXTJOIN(delimiter, ignore_empty, text1, [text2], …, [text252])
... where ...
1
vote
1
answer
147
views
Finding max number and location in multidimensional array in Matlab
I am attempting to find the maximum value and its location in multidimensional array using Matlab. There are functions findMax3, ...
6
votes
3
answers
2k
views
Dynamic array implementation using C++
I implemented a basic dynamic array using C++.
When deleting an element and shifting the others, the last element will be twice repeated (the original still exists after copying). I want to avoid ...
1
vote
1
answer
295
views
Find Kth Element in the merged two sorted arrays?
We have been given two sorted arrays and a number K . We have to merge the two sorted arrays in the sorted manner and return the element at the Kth position.
My approach is to use two variables ...
1
vote
1
answer
62
views
Convert string to object array javascript
I want to convert string to object array. Suppose I have following string.
const str = "someValue,display";
I want to convert it like following.
...
3
votes
3
answers
645
views
Find common timeslots for consecutive days
Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to ...
2
votes
2
answers
2k
views
Sort array of dates
I have this array with dates. All the dates are checked before creating the array with preg_match and check_dates.
GoodDates (
...
0
votes
1
answer
237
views
How to create an array with 10 elements based on a maximum value [closed]
I got a number that can range be either 10, 20, 30, 40... up until 100.
I'd like to make an array from that number. The array should be structured as follows:
If the number is ...
3
votes
1
answer
388
views
Grouping anagrams together from a string array
I wrote this code in c#. It is a question from LeetCode, number 49. Given an array of strings, group the anagrams.
The examples it gives are:
["eat","tea","tan","...
5
votes
1
answer
198
views
Nullable array wrapper class with small size optimization
I have an array wrapper class that I'd like to get reviewed.
There are two differences with other common questions on this site. First, my class needs to be "nullable", where a "null ...
4
votes
3
answers
832
views
FIFO array/queue
I'm new to programming and was tasked with programming a generic circular FIFO queue, without using anything but an underlying array and self-programmed methods. I still don't know how to approach ...
1
vote
3
answers
214
views
Replace array values with product of all other values
Need help to optimize the following code for lower time complexity:
...
2
votes
2
answers
105
views
Send an array of files and return the first one that exists
I have a little project, chuy, which is basically a copy of Make.
By request of users I have added support for toml configuration, since originally it only accepted ...
1
vote
1
answer
2k
views
PHP Group associative Array duplicates and make subarrays of different values
I have this type of table:
...
0
votes
2
answers
2k
views
1
vote
1
answer
446
views
Best way to cherry pick objects from array of objects
With this data I am returning one object per keyword prioritising preferedDomain string on domain and then its higher ...
1
vote
1
answer
137
views
How can I rewrite this typescript map to be more concise?
I have a short bit of TypeScript code that looks like the following:
...
2
votes
0
answers
389
views
Combining columns based on header names of an array
PROBLEM:
I need to merge the columns by identifying the headernames and they work as desired by using the below code.
The code is very inefficient as I am using an eval to accomplish the job and I ...
2
votes
2
answers
163
views
Complex Filter in one Opration
I am working on a Data-based application.
I wrote a code to filter the table.
The table has String and Numbers.
I some filter ...
1
vote
1
answer
413
views
Implement 2D and 1D std::array in opencl kernel
I am asked to implement the following part of code into kernel code. Actually, I have tried but not sure about the std::array.
This is the original code for the ...
2
votes
1
answer
425
views
table pagination
What I'm trying to do is quite simple: my table has pagination. So if I have 12 items to show and my max items per page is 10, I will have 2 pages, one with 10 records and another with just 2. I ...
1
vote
2
answers
1k
views
move duplicate items at the end of the array
I have array [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4] so I
want to move all duplicates at the end of the array [1, 2, 3, 4,1, 2,
2, 3, 3, 4, 4, 4]. is there is another best way to do the same Go
Time O(n)...
7
votes
1
answer
366
views
Create tweet threads from String in Java
I recently got this question in an exam, this is how I implemented, it is working fine. However, I would like to know if the code can be improved, as I think it for sure needs to be improved. The ...
1
vote
2
answers
223
views
How to take out attribute from two ArrayList of object which have different match in optimize way
I have two ArrayLists of objects and the after comparison I am taking out the value which has a difference based on the attribute.
So in my condition when the ...
1
vote
3
answers
109
views
Javascript: Reducing redundancy of notation nested value
Hello I have this function that looks for nested value 3 levels deep currently
...
1
vote
1
answer
71
views
Is Array Separable To Two List
The aim of the implementation is divide an array to two sub array which the total of the every sub array should be equal. If Array is dividable then method return ...
4
votes
4
answers
251
views
Better way to minimize array elements
I would like the array elements to minimize by preserving their orders. For example:
3,7,9,7 is given 1,2,3,2 is yielded
...
1
vote
1
answer
145
views
Java generic 3-median quicksort
My generic 3 median quicksort:
...
10
votes
4
answers
3k
views
First non-repeating Character, with a single loop in Python
I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop.
My thinking is, it would be easy to tell you what ...
2
votes
1
answer
86
views
Is this a reasonable way to test/compare javascript loop speeds?
I'm playing around with understanding array looping speed.
I'm trying to make the contenders equivalent and close to realistic.
Is this a good approach?
Are there other iteration approaches to test?
...
1
vote
4
answers
1k
views
Print a 10x10 times table
I have been on the C++ learning grind for the last 2 weeks using caveofprogramming videos so don't judge too hard if this seems like a dumb question.
My last lesson covered arrays and the assignment ...
1
vote
1
answer
3k
views
Google Foobar - "Distract the Trainers" [closed]
QUESTION:
You will set up simultaneous thumb wrestling matches. In each match, two trainers will pair off to thumb wrestle. The trainer with fewer bananas will bet all their bananas, and the other ...
2
votes
4
answers
306
views
To what degree is my VBA Array size function safe, robust, and performant
Coming from a Java/Scala background with a strong focus on OOP+FP, I recently started working with Excel+VBA to implement a front-end for a SaaS. It was like stepping way back in time, over two ...
1
vote
3
answers
369
views
1
vote
2
answers
127
views
Check URL for keywords [closed]
I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below?
...
5
votes
3
answers
564
views
HackRank - Array Rotate Optimization
I am working on a basic Array rotate code for a Hacker Rank challenge. The code is complete and passes all test cases, except for 2 which it times out on. I was wondering if there is a way to make ...
1
vote
1
answer
100
views
Multi-dimensional arrays exercise: Introduce married couples to each other
Following idea: There are three married couples and they have to be introduced another.
I have implemented this solution:
...
2
votes
1
answer
311
views
Turn an array of pairs of start and end points into an ordered series
Given an array of pairs, for example:
[["Denver", "Miami"], ["Miami", "Tulsa"], ["LA", "Okmulgee"], ["Mobile", "Portland"...
2
votes
2
answers
132
views
Print Binary coded decimal Numbering of a given input number
Example 1
input:3
output:0011
Example 2
input : 15
output: 1111
in the below example code 15 is input.
I have taken 8 4 2 1 as array for Binary coded decimal numbering
this code is working as ...
3
votes
3
answers
1k
views
Printing rotations of an array 7 times
Loop through a given array 7 times and print the following output:
int[] arr = { 9, 2, 7, 4, 6, 1, 3 };
...
11
votes
3
answers
2k
views
My blit function for my own graphics library
Here is a blit function for a graphics library I made.
I've built a small graphics library that uses an palette-indexed spritesheet to hold all of the game's sprites. The blit function copies parts of ...
3
votes
1
answer
348
views
PHP update multidimensional array values from same path multidmensional array
I need to update a multidimensional array by same key paths of a multidimensional array.
I think my code can be better condensed :
...