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
0
votes
2answers
71 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
2answers
857 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: ...
0
votes
2answers
32 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
1answer
46 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. ...
1
vote
0answers
31 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 return a ...
1
vote
1answer
71 views

Fancy new LAMBDA functions with variable number of arguments to mimic native methods - no VBA

The TEXTJOIN function has a really nice interface: =TEXTJOIN(delimiter, ignore_empty, text1, [text2], …, [text252]) ... where ...
1
vote
1answer
27 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
3answers
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
0answers
37 views

Counting Cram game positions in C

This code counts the number of possible positions in the game of Cram on a mxn board. EDIT 1: In the original question I mistakenly mentioned that this number is ...
1
vote
1answer
66 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
1answer
26 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. ...
2
votes
2answers
67 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
1answer
76 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 ...
2
votes
1answer
58 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","...
4
votes
1answer
105 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
3answers
277 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
3answers
96 views

Replace array values with product of all other values

Need help to optimize the following code for lower time complexity: ...
2
votes
2answers
60 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 ...
0
votes
0answers
41 views

Create a new array of an array of numbers and an array of objects whose key is used for search

I have an array requestArr in which there are objects with two values, also I have an array with objects itemsArr keys which is '...
1
vote
1answer
52 views

PHP Group associative Array duplicates and make subarrays of different values

I have this type of table: ...
-1
votes
2answers
75 views

Find the matrix row having the largest sum

...
1
vote
1answer
60 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
1answer
54 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
0answers
36 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
2answers
62 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 ...
0
votes
1answer
43 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
1answer
41 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
2answers
223 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)...
6
votes
1answer
106 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
2answers
49 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 ...
0
votes
3answers
50 views

Javascript: Reducing redundancy of notation nested value

Hello I have this function that looks for nested value 3 levels deep currently ...
1
vote
1answer
47 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
4answers
143 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
1answer
36 views

Java generic 3-median quicksort

My generic 3 median quicksort: ...
10
votes
4answers
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
1answer
54 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
4answers
87 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 ...
3
votes
1answer
144 views

Google Foobar - "Distract the Trainers"

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
4answers
182 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
3answers
101 views

Generating a number of students and assigning them

...
1
vote
2answers
87 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? ...
1
vote
3answers
118 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
1answer
54 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
1answer
54 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
2answers
90 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
3answers
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
3answers
1k 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 ...
1
vote
1answer
34 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 : ...
4
votes
1answer
96 views

More efficient way to create an ASCII maze using box characters

I've written a C# program to generate a random maze, and then draw that maze in the Console mode using box-drawing characters, e.g. ─ │ ┌ ┐ ┬ ┼ etc. It works fine, as below, but I'm not convinced that ...
2
votes
0answers
45 views

editing the array I've included instead of editing the file of included array php

In order to reduce time complexity, instead of loading (and then dumping to use it for later) the whole file into an array (It would be O(n) with n=number of lines), I have saved it as array into a ...

1
2 3 4 5
40