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.
3
votes
1answer
12 views
Counting sort implementation in C
I've just implemented counting sort in C and would like to hear your opinions on it. As I'm usually being rather picky when rating other people's code, please go ahead and be picky, too -- I will try ...
2
votes
1answer
20 views
Isomorphic string in LeetCode
I solved this problem:
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to
get t.
All occurrences of a ...
1
vote
0answers
17 views
Splitting an array into stride by 2
i've written a basic function to split an array into stride by 2:
...
5
votes
1answer
66 views
Connect Four Game (Java)
I wrote this program as an assignment for an introductory programming course in Java, which I then decided to improve past the minimum assignment requirements.
It allows two human players to play ...
0
votes
0answers
30 views
Find max in-order difference in array
Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j].
If there is no solution possible, return 0.
Example :
A : [3 5 4 2]
Output : 2
for the pair ...
7
votes
2answers
607 views
To the right, to the left, now rotate
I was working on HackerRank: Circular Array Rotation which is about coming up with an efficient algorithm for array rotations in right-ward manner.
John Watson performs an operation called a right ...
3
votes
0answers
41 views
finding substrings within arrays - javascript
I need to find the substrings within my array. If I have an array: ["abc", "abcd", "abcde", "xyz"], my method should return the array members: ...
0
votes
0answers
32 views
An attempt at a cookie wrapper
This an attempt of a cookie wrapper of sorts. It has no real purpose nor do I encourage anybody to every use it in a production environment. It was made for fun, at best for practice.
The purpose is ...
3
votes
1answer
50 views
Hackerrank Sparse Arrays Solution in Java
I've just solved this problem and I hope you guys give me any feedbacks to make my code be better. Thanks a lot!
Problem: There are strings. Each string's length is no more than characters. There ...
0
votes
0answers
10 views
from json array to variable or mysql [closed]
I have this script to display some value from a json file:
...
-1
votes
4answers
62 views
Unique values of an array
I'm curious if there is another way to code this. Could it be done with a while loop for instance?
...
0
votes
0answers
11 views
Array Menu Switch Options, Black Executing Program [closed]
This is some code put together using an array to store numbers using a menu to let the user input, delete, and sort data. The compiler doesn't seem to have any issues, but executing the program ...
6
votes
0answers
47 views
Battleships Player vs Computer Algorithm
I am a Year 12 student studying CS for my A-Levels. I have had previous Python experience but it is obviously not to professional/industry standard. Therefore, my goal for this review is for my code ...
3
votes
1answer
44 views
List abstraction using array
Following this reference, below is the list abstraction implementation using array,
...
-4
votes
0answers
20 views
Merging of nested arrays based on key value [closed]
I have to merge 2 arrays with key value as follows:
...
0
votes
0answers
19 views
UDFs with Header-Case selection is too slow
I am working at a project where we implemented 10 different UDFs which gave us high flexibility and a clean code but basically screwed the file up as the file got super slow in the end: The problem is,...
0
votes
1answer
43 views
Searching in array by key => values
I need to write a function that searches the two-tier board according to certain parameters, which works, but I question whether there is a simpler, lighter way to perform this task.
...
1
vote
2answers
78 views
Merging K Sorted Arrays
My aim is to merge k different sorted array with unique elements and I want a code review about it, here is my code below which is written in java;
...
2
votes
0answers
32 views
Optimize iteration over numpy array with vectorize [closed]
I have the following method which deals with numpy arrays to find the cumulative minimum from each element and its neighbors above:
...
4
votes
1answer
65 views
Finding the indices where a selected player appears in a list of hashes
I have an array of hashes in a YAML file. When I run the code below it is VERY slow. My YAML pwsarr.count is about 2000.
I am somewhat new to Ruby so I don't know ...
3
votes
3answers
31 views
Summing durations associated with each MAC address in a MongoDB result
I have a script which get data from MongoDB in the form of array and show the result. The array has a number of records in the thousands. A sample array is as follows:
...
2
votes
1answer
67 views
Find the longest subarray with sum less than K
The problem consist of finding the longest contiguous subarray with a sum less than a given integer K.
The input data are:
K - ...
3
votes
0answers
49 views
Perlin Noise Generator - Round 2
After a good first review, I've much improved my code which is generating Perlin Noise as a means of 2-D terrain generation. My first attempt was not very well met because at the time it was a lot ...
6
votes
4answers
115 views
Repeatedly partitioning an array equally as far as possible
I solved HackerRank Nikita and the Game. The implementation is correct as program passes all test cases.
Nikita just came up with a new array game. The rules are as follows:
Initially, ...
1
vote
2answers
106 views
Perlin Noise Generator
I'm porting a 2-D Terrain Generator from Python to C++ as Python is too slow due to the number of features that have been added.
I'm new to C++ and would like to know of any criticisms that you can ...
3
votes
0answers
20 views
Extending Array to make a stack that bubbles unused objects up and active object down
Array.prototype.fastStack
To combat GC and its impact on animation I created Array.fastStack that adds to the array prototype.
It's a sort of stack that bubbles ...
3
votes
1answer
53 views
Unfold a 2D array spiral in C#
The purpose of this function is to turn a 2D array of sorts into a single-dimensional array by reading it in a spiral fashion.
In the array:
1 2 3
4 5 6
7 8 9
...
5
votes
2answers
101 views
x86 assembly function that determines whether an array is continuous
I wrote an x86 assembly function using MASM that tests for whether or not an array is continuous. That is to say, if an array with length n that starts with the value k, all the subsequent entries in ...
5
votes
1answer
711 views
C program circular array rotation
I'm trying to solve a Hackerrank problem where you perform k array[n] rotations, and at the end, ask for ...
0
votes
1answer
40 views
Preferred implementation of `Array<T>::operator=(const Array<T> & rhs)`
I have a custom template class Array<T>, and am currently implementing the assignment operator.
However, I've come across a design decision: When assigning ...
5
votes
0answers
33 views
Grouping, merging and mapping with a timetable
I want to create a "timetable" for some shop. It should look like, "days - hours".
I get response from the server in this way:
...
0
votes
1answer
50 views
2
votes
4answers
148 views
Circular array rotation Java
I have a solution to the HackerRank Circular Array Rotation challenge. It passes 7 test cases out of 15. The rest of them are getting timed out. I think it's because of the huge data set that has ...
1
vote
3answers
61 views
Finding the nth machine encountered on the journey
Recently I came across this problem in the IARCS server,here is an little excerpt from it,
A well-known bandit who used to haunt the forests around Siruseri was
eliminated by the policemen a few ...
2
votes
0answers
38 views
Converting [UInt32] -> [UInt8] -> [[UInt8]]
I am trying to speed up my current implementation of a function that converts [UInt32] to a [UInt8] which in turn is split up ...
1
vote
3answers
54 views
Look for patterns in the keys of an array, to group them in a new array
I am working on a function that will take a an array of options. These options are retrived from a database, and could have other options inputted throughout the system. When adding my options, I am ...
3
votes
0answers
111 views
Google Foobar power_hungry challenge
I'm trying to do the power_hungry challenge of Google FooBar. Here's the problem for context:
You need to figure out which sets of panels in any given array you can
take offline to repair while ...
4
votes
3answers
177 views
Tic-Tac-Toe game simulator in Java
I've completed this Tic Tac Toe simulator in java and so far it's working. It's just supposed to generate a pre-played game and announce the winner. I'm required to use a 2D array and this is the way ...
3
votes
1answer
118 views
Simple Employee Records Program
I am a beginner Java programmer. I have just finished up an assignment and would appreciate some advice and/or criticism on my program. For context, I have the assignment details, followed by the full ...
1
vote
1answer
71 views
Array choice based on template specialization
I've got these two template functions responsible of adding/removing actors in-game in GameEngine.h:
...
2
votes
2answers
66 views
FIFO Queue Implementation
My Implementation of a FIFO queue. I am mainly curious about my initialization of empty generic arrays.
...
4
votes
4answers
78 views
Transposing a PHP associative array
The purpose of this code is to change each column to a row, and assign keys to each value for the new array according to the old array. I would like to know if there're other ways to optimize it.
<...
2
votes
1answer
101 views
Find the number of K-Complementary pairs in an array
Below is the program to find k-complementary pairs: K = A[i] + A[j];.
...
4
votes
1answer
85 views
2 Player TicTacToe Game
I am a beginner Java programmer and I have just finished creating a simple 2 player TicTacToe game and would appreciate some feedback/advice on how to make it better.
...
0
votes
1answer
49 views
Recovering permutation from its image sequence
Recently while practicing I came across this problem , here is an excerpt from it,
A permutation of the numbers 1, ..., N is a rearrangment of these
numbers. For example
2 4 5 1 7 6 3 ...
1
vote
1answer
102 views
Integer sum program
This is a little assignment I am working on. I am a beginner Java programmer and would love some advice on how to improve this code.
For more context, here are the assignment details:
Create a ...
11
votes
2answers
132 views
Python ASCII-Art Table
As a part of a console utilities module, I created a function that takes a table in the form of an array of arrays, and generates an ASCII table with the given contents.
I've also added the options ...
0
votes
1answer
27 views
Shifting an array with less touches
I have an array that I am shifting by a certain number of spaces. I am wondering if there is an better way to do the shift with less touches. Here is my code
...
4
votes
2answers
133 views
Dynamic Array container in macros
The code below is an attempt to mimic std::vector from the C++ standard library in the C language.
The implementation is purely macros, in the C99 dialect, and ...
-1
votes
2answers
46 views
k times left rotation of array [closed]
Left rotate array (a), k times, n is size of array.
I know, we can calculate n, but prototype is mentioned in respective question.
...