Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

6
votes
2answers
146 views

Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
3
votes
1answer
68 views

Array Partitioning

I have a method in Java that I'm using to partition byte[] arrays into a number of fixed-size sub-arrays. It's not necessary for the last array to be that size, but all preceding ones must be, and the ...
4
votes
1answer
98 views

“What To Do” App

I am starting to build up my portfolio, so I am starting to build projects whenever an idea pops up in my head. So, I decided to build an app that helps you decide what to do. Basically how it works ...
3
votes
2answers
50 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
4
votes
2answers
84 views

Minimum difference between numbers in a file

I'm learning Java and I created a simple solution for the following problem: Given a file [filename].txt such that each line has the format ...
-1
votes
0answers
19 views

Create array that fills with series of random numbers, prints the elements of the array and more [closed]

I need to create a C++ program that creates an array, fills the array with a series of random numbers, prints the elements of the array to cout, identifies the largest element in the array and prints ...
0
votes
0answers
33 views

Identifying objects as some type of enum

Please review my code. It works as it should but I think about making it more pretty or optimal. This method should take in some IEnumerable of ...
2
votes
0answers
13 views

Drawing an ASCII grid in Ruby based on a 2D array

I'm writing a function that renders a grid using ASCII line-drawing characters, based on a provided 2D array (or array of arrays), with each top-level array representing a row, and the items inside ...
4
votes
2answers
56 views

Checking if an array can be rotated to equal another in JavaScript

I needed to write a function in JavaScript which checks if any rotation of an array is equal to another array. By rotation, I mean: ...
4
votes
2answers
102 views

Finding the second largest value In an Array

findSecondLargestNumberInTheArray() method returns the second highest number from an array. Could you please review this code to enhance performance. ...
0
votes
1answer
29 views

Hash Tables: Ice Cream Parlor solution in javascript [closed]

I tried solving the Hash Tables: Ice Cream Parlor question in javascript: ...
3
votes
1answer
49 views

Getting angle between all points in array

I have got some code that calculates the angle between all of the points in an array. It works, but it is quite slow. This is because it has complexity O(n^2). It has to loop through the array and ...
7
votes
1answer
210 views

Calculating the number of rooms in a 2D house

I stumbled upon this problem on cses.fi (a problem set for the Finnish Olympiad in Informatics. This problem is in finnish so I'll translate it). I'll describe the problem, present the code and think ...
4
votes
4answers
87 views

Filtering a name Array in JavaScript

I was wondering if there is a better, more elegant way to write the following JavaScript code block: ...
3
votes
1answer
42 views

Counting sort in C, revised

This is a revised follow-up to this question. I have implemented most of the suggestions in the accepted answer. I am interested to see what I could improve in my code and what I could do to make it ...
0
votes
1answer
49 views

Counting contiguous subarrays with a negative sum

I'm doing a coding challenge that asks to count the number of contiguous subarrays that have a negative sum: A subarray of an n-element array is an array composed from a contiguous block of the ...
2
votes
1answer
31 views

Generating random N-dimensional arrays

For this code challenge, I want to create a performant function that creates a rectangular N-dimensional array. (min_dim_size, max_dim_size) is the span size of every dimension. So ...
2
votes
2answers
32 views

Algorithm that parses through input of points and finds distance

I'm wondering if someone could take some time to review this script. I'm parsing through a list of points of any length and calculating the distance. I'm wondering how to make my code better/more ...
5
votes
4answers
501 views

Summed absolute difference of two array

Question (SAD Queries on CodeChef) The Summed Absolute Difference (SAD) of two arrays. Given arrays (1-indexed) \$P\$ and \$Q\$ of lengths \$p\$ and \$q\$. Given a collection of \$n\$ arrays ...
1
vote
1answer
46 views

Possible letter combinations of a dial pad in linear time using a recursive approach

Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
1
vote
3answers
74 views

Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be ...
0
votes
2answers
121 views

Add item at the beginning of each inner array in jagged array

So, there is a big jagged string array (~ [120] [1 000 000]) here that represents data from an excel worksheet ( columns / rows). Task: We have to append items at the beginning of each inner array. ...
1
vote
1answer
26 views

Primitive ArrayList Implementation

I have implemented a primitive ArrayList class in C++ as part of an attempt to learn about data structures and their optimizations. It currently has: Constructor/...
5
votes
6answers
1k views

Hacker rank 30 days of code Maximum Sum of Hourglass

I came up with this code as a solution to a contest question. The original question can be viewed here for attribution sake: Hackerrank 2d array problem Sample input is like this: ...
1
vote
1answer
81 views

JavaScript Determine if Array has Almost Increasing Sequence

A coding challenge on a website says to determine if an array would have an increasing sequence if one element were removed from that array. Here is the function: ...
3
votes
1answer
42 views

Removing leading new line from byte[]

Given this piece of code, what is a better way to write it (cleaner). It is taken for granted that data will not be null, nor its length will be 0, so this check is ...
2
votes
2answers
260 views

Determine if Array has an Increasing Sequence

I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence. For the sake of better time performance I made the ...
1
vote
1answer
70 views

Checking whether an array contains a value or another array

I'm designing an isIn method that takes a value:any and checks whether it exists in an array. It's working, but I'm wondering ...
3
votes
2answers
93 views

Make an Array Reactive (Observable)

I have written a simple JavaScript function to make an array reactive (i.e. observable). Is there anything I could improve? What the code does is take an array, a callback and a ...
4
votes
0answers
37 views

General use multi-dimensional container using operator[]

This is a followup to a previous question of mine on same subject. Context I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional ...
2
votes
4answers
76 views

Calculate min, max, mean and median out of array Version 2

This question is a follow up of: Calculate min, max, mean and median out of array I took all the suggestions an reworked the code. Like the description of the excercise suggests i only use one ...
1
vote
3answers
88 views
10
votes
3answers
1k views

Calculate min, max, mean and median out of array

Another C exercise: Write a function that takes an array of 'ints' as its input and finds the smallest and largest elements. It should also compute the median and mean. Use a ...
0
votes
2answers
105 views

Finding Repeat and missing numbers in an array

Problem Statement: You are given a read-only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. ...
4
votes
1answer
108 views

Finding the smartest set from an array of numbers

Is there any way to make this program run in better time ? While running, it is taking 1 second for the sample test case to pass and 5-10 seconds for the rest of the test cases. Problem statement ...
1
vote
1answer
53 views

Count the number of ways to make a given sum using one number from each array

I have three arrays, each of which contains only numbers. Given a target number, I need to return the number of ways I can make that sum, using exactly one number from each of the arrays. For example:...
6
votes
2answers
48 views

Find select values on one worksheet and copy to a second

In the Calculator worksheet of my spreadsheet, for any appliance type present in a building being studied, users enter a quantity. There are 18 different appliance ...
4
votes
1answer
76 views

Algorithm for tagging list of substrings from a list of strings

I have a list of utterances(strings)/corpus as the follows, ...
4
votes
3answers
124 views

Determine whether to push or update object in array based on unique ID

I am trying to write a basic function that will decide whether the object already exists in array of objects based on unique id that is inside this object as a property. Upon searching I came up with ...
9
votes
2answers
158 views

Multi-dimensional container using operator[]

This is a late followup to a previous question of mine on same subject. Context: I want to have a tool that allows to use all the C++ goodies (algorithms, for loop on containers, etc.) on a ...
5
votes
3answers
128 views

Shuffling an array keeping some elements fixed

The task is simple to understand: how to shuffle an array keeping some elements fixed. Let us take an example: starting from the array [1, 2, 'A', 3, 'B']. Having ...
5
votes
2answers
91 views

Writing Merge Sort in C++

I am learning programming online and currently watching CS50 lectures, in third lecture, professor introduces us to merge_sort though only through pseudo code, so I wanted someone to review my ...
-1
votes
1answer
53 views

C++ std::array reimplementation [closed]

As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation? ...
2
votes
2answers
90 views

Wrapper for a raw array so that it can be passed to templates expecting Standard Library containers

I am working with a code base where unfortunately I cannot replace all raw arrays with std::array. The spec provides no guarantee that the memory layout of a ...
5
votes
1answer
171 views

Encrypt a byte array

This code is a Frankenstein. I found ten examples done in ten different ways and my requirements were slightly different so even if they were reliable they weren't a copy and paste solution. Encrypt ...
5
votes
2answers
93 views

Read an image with ADNS2610 optical sensor and Arduino Uno

Preliminaries I have optical sensor ADNS2610 (see datasheet here). There are a few problems which it can be used to solve, but for now let us focus on getting an image from that sensor. This sensor ...
9
votes
3answers
634 views

print array of previous smaller elements

I am solving interview question from here. Problem : Given an array, find the nearest smaller element G[i] for every element A[i] in the array such that the element has an index smaller than i. ...
7
votes
2answers
151 views

“Ease the Array” challenge

I'm working on this challenge: Given an array of integers of size N. Assume ‘0’ as invalid number and all other as valid number. Write a program that modifies the array in such a way that if next ...
3
votes
4answers
376 views

Shift one value of array values to the beginning

Given an integer $value in the range of 1, 2, 3, I want to get an array that starts with ...
1
vote
1answer
265 views

Finding the largest value in a 2D array

I'm pretty new to Java and programming in general and I'm doing practice problems from my textbook over the summer to try to get ahead. This is a simple program that finds the largest value in a 2D ...