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.
0
votes
1answer
23 views
Generating variables to be named, filled in and operated on the fly in python
I am very new to python and trying to refactor my code which is ripe for error.
Currently I manually name a bunch of arrays:
...
6
votes
1answer
89 views
Implement 3 stacks using a single array in C++
One of the questions that is presented in Chapter 3 for Cracking the Coding Interview is this:
Describe how you could use a single array to implement 3 stacks
I'...
1
vote
2answers
57 views
Generating random numbers and decks of cards
So I have some code here:
First a simple random # generator and a array-choosing function:
...
5
votes
2answers
116 views
Printing an N*N array in the rectangular/circular/spiral fashion
The problem is to print an N*N array and fill it with numbers(starting from 1 at (0,0)) in the rectangular/circular/spiral fashion, going inwards, ending at the N*N value.
Also find and count the ...
7
votes
1answer
84 views
Cipher text using a 2D array
I have a simple program which ciphers text using a 2D array. You specify what letters to replace with what and it does it.
I understand the code is very repetitive and that I should probably use ...
2
votes
1answer
66 views
Check deep object property and find duplicate value
I use the following code to find if there is duplicate value in property path:
...
0
votes
1answer
49 views
Follow up: Simplified Implementation of ArrayList in C++
This question is a follow-up to the my earlier code posted here. In the original question, I created a simplified version of C++ std::vector/...
4
votes
2answers
105 views
If zero found in Matrix. make entire row & column zero
Problem is - If in an MxN matrix, a zero is encountered, the entire row and entire column should be set to zero.
Example -
8 4 2
2 3 7
1 0 1
9 8 4
...
1
vote
0answers
35 views
Re-Ordering the draw order for my entities in my Isometric game
Introduction
I am making a 3D Isometric game. I have a Tower, filled with Block's in a 3D ...
7
votes
3answers
176 views
Simplified implementation of std::vector in C++
I implemented a simplified version of a C++ std::vector/ArrayList learning from this link. From it, I tried to write an ...
1
vote
3answers
324 views
Combine neighboring parts of an array based on a condition
I have written this code which takes a one dimensional array, for example:
{"abc","ade","sss","fgw","asd","lka","o"}
and turns it into an array of arrays, ...
3
votes
1answer
60 views
3Sum implementation
I have recently started to work through the problems on Leetcode, for the sake of bettering my own skills as well as preparing for interviews. I was faced with the 3Sum problem which is:
Given an ...
2
votes
1answer
56 views
Partial ArrayList implementation in C++
I've implemented a C++ version of Java ArrayList. It doesn't contain all the functionalities such as AddAll and iterators and such, but I still would appreciate criticism to my code correctness, style ...
1
vote
1answer
115 views
Function to find a substring within a string [closed]
I've just completed an exercise in which I had to create a program that searches for a string within another bigger string.
If the substring exists then it is outputted to confirm and the starting ...
2
votes
2answers
40 views
Filtering array by list of keys in PHP 5.5
I have an associative array with data (let's say language codes and descriptions) and a second array with allowed keys (lang codes). I want to filter the data array by these allowed keys.
The ...
0
votes
0answers
30 views
HackerEarth Prateek and his Friends non-contiguous
How to solve this problem for non-contiguous range?
Prateek wants to give a party to his N friends on his birthday, where each friend is numbered from 1 to N. His friends are asking for a gift to ...
1
vote
1answer
243 views
3
votes
4answers
72 views
Unit testing for concatenating two int arrays
Using Java 1.8, I created the following implementation to concat two int arrays:
...
0
votes
1answer
32 views
2
votes
2answers
83 views
Implementing a Sort for an Array
Yesterday, I gave an interview after a long time, and I was asked a question which I couldn't solve on the spot.
I had to implement a sort function for a Array of strings in JavaScript, with the ...
10
votes
7answers
1k views
Generate random binary arrays
I am fairly new to C++ programming and I, so far, love it. I just have been trying to make sure what I am doing is fast, unique, readable, and efficient. Is there anyway I can improve this code, or is ...
1
vote
1answer
42 views
Finding unique items in the array
I was reading this code where author claims that its the fastest implementation which I doubt, hence I decided to write my version of the same problem.
...
1
vote
1answer
66 views
Removing a specific character and its neighbors from a string
Assume we have an string that contains the character 'c'. This character can be located anywhere within the string. The exercise ...
2
votes
1answer
63 views
Algorithm for two languages that merges and sorts two arrays without mutating one
This algorithm, which I have included its flowchart as well, takes an array of A[n], which is unsorted and unmutatable and an array of ...
5
votes
3answers
56 views
CopyOf2DArray (Values Only)
Purpose:
Given a 2-Dimensional Array, return a copy of the Array. In VBA, if I just
Set newArray = oldArray
then newArray is ...
6
votes
1answer
132 views
`Piece` class as part of implementation for the Tetris game
Here is my Piece class as part of implementation for the Tetris game. Critics of any kind and levels are very welcomed. If possible, I want my code to face the ...
3
votes
0answers
23 views
Create archive webpage for newsletters based on nested array
I am creating a webpage for my newsletter archives. The archives are divided by year (currently there is only 1, but there could be many), then by topic, before listing each newsletter. There will ...
2
votes
2answers
123 views
Reverse string in JavaScript without using reverse()
I have to reverse a string in JavaScript and cannot use the built in reverse() function. It does not seem efficient to have to create two arrays but is there a ...
4
votes
2answers
96 views
Find maximum value of Point represented by an Array of values for each coordinate
Suppose there is an array A = {3,2,5}, then points for this array correspond to indexes (i,j) where ...
7
votes
2answers
340 views
Validate whether a ransom note can be made from a dictionary of words
For simplicity, it is checking whether the characters in a string (that needs to be created) are present in a larger string (dictionary). Would a character array of the letters make sense here, or ...
2
votes
1answer
33 views
Converting values to Dates in column
I'm not happy about my code, but is the better way that I find,
I'm not happy because I see that there are many code repetitions and when any change is easy to make mistakes. Do you think you can do ...
3
votes
1answer
134 views
A small generic array in C
The generic arrays in C I found on the net used either of these methods:
The preprocesser with #define and #include (a lot of ...
4
votes
3answers
98 views
Finding the frequency of an element in a sorted list of integers
Input: Array of sorted integers and an element to check the frequency for
Output: Frequency of the element
...
1
vote
5answers
95 views
Ruby array search, returning either a result with a good score or the last result
I have an array of hashes, each of which has two attributes: "title" and "Zscore". I want to return either the result of ...
2
votes
2answers
71 views
Create a calendar application to check the scheduling conflicts of meetings
The purpose here is to find if there is a conflict in the given set of start and end times of the meeting time slots listed.
Input: Start and end times of meetings
Output: True / False for conflicts
...
6
votes
5answers
281 views
A custom String Builder implementation
Two code files below : the actual logic & the test logic.
Core Logic
...
3
votes
3answers
92 views
Checking if numbers in array are sorted or reverse sorted
I would like to determine is an array of numbers, is always increasing (for all x, x+1 >= x) or always decreasing (for all x, x+1 =< x). If so return true. Another way to state the problem is, ...
4
votes
1answer
67 views
Max difference between two array elements
Can I get feedback on below code? Problem statement is Maximum difference between two elements such that larger element appears after the smaller number
Would this solution be still considered O(n) ...
11
votes
5answers
765 views
Removing n elements from array starting from index
This method removes n elements starting from a given index, from an array of a given type. If n is positive it removes elements forwards, if it is negative it removes them backwards (e.g. for an array ...
0
votes
0answers
15 views
Add and merge 2D array items so no nested duplicates on the outer array
this.collisions is a 2D array containing a list of collisions that, when bodies collide, they should be added to it. Here's an example:
...
3
votes
3answers
176 views
“Prev” / “Next” buttons for a circular list
I have an array of strings and on click of the "NEXT" button it displays the next array item in a <p> tag while on click of the "PREV" button it displays the ...
3
votes
1answer
60 views
Merging multiple sorted arrays into one sorted array
I would like to merge multiple arrays that are already sorted, into one sorted array.
My arrays look like this :
...
3
votes
1answer
99 views
Enum string parse and get custom attribute assign to array
I wrote a code which:
- parse string to my enum
- get description from enum
- assign to string[] array
...
-1
votes
2answers
71 views
Finding consecutive occurrences of a value in an array
Given an array, return True if the array contains consecutive values:
...
0
votes
1answer
32 views
Iterate through a 2D array. Kotlin extension method
Simple extension method for Kotlin. Should perform an action on every element in a 2d array. i.e. An array of arrays.
I have made the assumption that because the receiver type is defined as an array ...
1
vote
2answers
154 views
Random iteration over an array using divide and conquer
I have created a utility class which allows random iteration over an array.
The idea is pretty much a divide and conquer approach.
...
5
votes
3answers
145 views
Bubble Sort in Objective-C
Following is Objective-C method implementation I did for one of the most simplest sorting algorithms, Bubble Sort to sort an array of integers.
Note:- I have defined it as a static method in the ...
3
votes
1answer
40 views
Access an associative array value given an array of keys in PHP
I have an object which stores an app configuration in an associative array, as this:
...
6
votes
2answers
99 views
Find number of plus in a 2d array
Problem
CharGrid
The CharGrid class encapsulates a 2-d char array with a couple operations.
int countPlus()
Look for a '+' pattern in the grid ...
6
votes
2answers
117 views
Longest palindrome in an array
I am new to programming, and think this code could be improved upon. Any suggestions?
...