Questions tagged [vectors]

Vectors are sequence containers representing arrays that can change in size. For questions about geometric or algebraic vectors, use [coordinate-system] instead.

Filter by
Sorted by
Tagged with
1 vote
1 answer
101 views

Positive Segments

I'm trying to solve the following question: You have an array A of size n, containing −1 or 1 only, and s segments (not necessarily different). Each segment is defined by 2 integers li and ri (1 ≤ li ...
driver's user avatar
  • 212
-2 votes
1 answer
54 views

Market Portfolio Binary Search Tree [closed]

I'm trying to solve the following problem here: First line of input contains the number of days D. The next d lines contains a character c and a number x. If c is B, then buy stock . If c is S, then ...
driver's user avatar
  • 212
4 votes
2 answers
535 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
4 votes
1 answer
105 views

C++ custom vector class implementation

I've developed a custom vector class in C++, complete with functionalities like assignment, push_back(), emplace_back(), pop_back(), clear(), and size(). I would greatly appreciate any feedback on ...
Jacob's user avatar
  • 111
8 votes
2 answers
256 views

C++ std::vector Implementation

Implementation of the vector class in C++ for learning purposes. Tried to implement interesting parts from the API shown on cppreference.com, but some elements like ...
jdav22's user avatar
  • 319
4 votes
1 answer
377 views

C23 Vector Macro Implementation

I'm trying to implement a simple type-generic Vector with macros using the newest features of C23. Looking for any advice about macro design and pitfalls because I generally avoid macros at all costs. ...
Biggs's user avatar
  • 143
1 vote
2 answers
52 views

Implementing a function that takes in 2 collections of strings and compares them as if they are unordered in Rust

I'm new to Rust and I would like to implement a function to compare 2 collections of strings. The function should compare them as if they are unordered. In Python, I would implement something like ...
James's user avatar
  • 13
7 votes
6 answers
1k views

Compute "negative" version of vector of vectors

Given a std::vector<std::vector<double>> (e.g., representing some points in a space with D dimensions), I want to ...
Filippo Bistaffa's user avatar
3 votes
2 answers
254 views

C macro based dynamic array library

This library is a fork of eteran/c-vector. It is macro based, so that it is generic, without void pointers and additional functions. This of course means that it has the downsides of macros in C. The ...
DuckHunterZx's user avatar
2 votes
1 answer
96 views

C generic typesafe dynamic array (vector) try 2

The previous generic dynamic array I asked a review for here was written using only the preprocessor and so while the array itself was type-safe, all the manipulating macros where not. In this try I ...
Itai Nelken's user avatar
2 votes
2 answers
80 views

Follow-up about computing lp norm with MPI

As pointed out in the answer by Victor Eijkhout to this question, the fact I am broadcasting the same vector to each process is against the MPI principles and, most importantly, will be a bottleneck ...
bobinthebox's user avatar
2 votes
1 answer
347 views

Compute lp-norm of a vector in parallel with MPI

I'm trying to solve the following exercise: Compute in parallel with MPI the lp norm of a vector of a predefined size N ...
bobinthebox's user avatar
2 votes
1 answer
104 views

Built a Vector2 class with easing functions, that can be unpacked

...
DracoDaine's user avatar
4 votes
1 answer
183 views

Growable vector on the stack with fixed capacity

Implements most (if not all) applicable member functions from std::vector and std::array Compatible with C++11, C++14, C++17, C++20 [] operator allows unchecked access, all other member functions ...
AdamF's user avatar
  • 43
0 votes
1 answer
50 views

Protein Translation Learning Exercise from exercism.org

I'm learning Rust by solving exercises from different tracks on Exercism. The below code is an implementation of "Protein Translation" from the Python track. I split ...
Saurabh's user avatar
  • 435
1 vote
2 answers
103 views

Collect gaps in a number sequence in Rust using Vec::windows

I have the following code which collects gaps in a number sequence into a separate vec. There will never be a case, iterating over a ...
Nic's user avatar
  • 201
1 vote
1 answer
73 views

General purpose 2D grid

I am developing (WIP) a mine sweeping game to get more familiar with Rust. I decided to represent the mine field as a 2D grid. While developing I realized that this grid can be outsourced as a general ...
Richard Neumann's user avatar
1 vote
1 answer
282 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
Vaibhav Vishal Singh's user avatar
1 vote
1 answer
448 views

Sort and search vectors by different criteria

Class class Player { std::string name; int score; int id; }; I thought about how to write a code to sort and search vector ...
MeoH's user avatar
  • 11
6 votes
0 answers
89 views

Chapter 8 Challenge: Add employee names to a department

The boring but exciting challenge: Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
lml's user avatar
  • 61
3 votes
1 answer
456 views

Which fruit fall onto my house?

I am following a question on a programming challenge website (here's the original reference). What I have is a house (start & endpoint) and some types of trees at their respective location points. ...
Hiro 's user avatar
  • 33
3 votes
1 answer
82 views

C Typed Vector that implements type-safety, encapsulation and lazy initialization

C Typed Vector I wasn't happy with the various dynamic array / vector implementations in C, so I made my own. In general, I'm not the biggest fan of C-preprocessor madness, but alas for this ...
Julius's user avatar
  • 171
1 vote
2 answers
885 views

Table data structure in C++ using a vector of vectors

I'm learning C++, and now I have to implement a table data structure. I don't know a lot about C++, so I have implemented using a vector of vectors. To access the rows of the tables I have defined ...
VansFannel's user avatar
4 votes
2 answers
1k views

Custom implementation to provide an immutable range of a vector without copying it

Edit: A new and improved version can be found in this question, based on the feedback! I needed to pass a const reference to part of a std::vector without copy. ...
Dávid Tóth's user avatar
2 votes
1 answer
144 views

Intersection of 2D vector equation straight lines

I know the vectors that describe two perpendicular lines, $$\mathbf{a} + \lambda\mathbf{d}$$ and $$\mathbf{b} + \mu\mathbf{d'}$$ I've written a JavaScript function to get the coordinates of the point ...
theonlygusti's user avatar
1 vote
2 answers
63 views

RE: Find maximum value of recursively-defined "fusc" function

Continued from the previous post - a brute-force approach to calculating all the vectors from 0 to n. I've come up with yet another solution, after I've realized that the vector takes up too much ...
Ashvith Shetty's user avatar
13 votes
4 answers
4k views

Vector Implementation in C

I made a somewhat simple vector implementation in C. Right now I only have around 5 features (making a vector, adding elements, removing elements, changing elements, deleting the vector). I'm proud of ...
dareesome's user avatar
  • 471
0 votes
2 answers
874 views

Separating odd numbers and even numbers into two vectors in C++

I'm learning C++, and would like some guidance. I'm pretty sure I'm doing something wrong. This algorithm runs in O(n) time and uses O(n) external space. Could I make a more efficient algorithm for ...
Asher I's user avatar
  • 13
4 votes
5 answers
2k views

C++11 Custom Vector Implementation

This was my solution to an interview question: Q: Implement an std::vector style container (does not have to be exactly compatible) with a fixed buffer and the following requirements and restrictions: ...
Dávid Tóth's user avatar
4 votes
1 answer
297 views

Algo to return a vector of available time slots for scheduling a meeting between two persons

There are 2 persons and their already booked meeting schedule is given and also time bound for both the person is given. Now, we want to schedule a meeting between them in an available time that suits ...
Lame Things's user avatar
2 votes
2 answers
182 views

An implementation of Uber's “Fare Estimator”

CodeSignal put out a challenge by Uber that involves writing a "fare estimator" that involves a function dependent on cost per minute, cost per mile, ride time and ride distance. The formula ...
Aleksey's user avatar
  • 153
5 votes
2 answers
241 views

C++ Connect-four game with little AI (Version two)

Here is the improved code ...
Ahmed Elsayed's user avatar
1 vote
1 answer
627 views

C++ vector bubble sort in my edition

I made a small adaptive function that sorts vector: ...
Jenia's user avatar
  • 197
6 votes
2 answers
530 views

Improving C++ Connect-four game with little AI

Here is the code for the game : ...
Ahmed Elsayed's user avatar
4 votes
4 answers
5k views

Efficiently splitting a string in C++

I've made a splitString() function which receives a character and a string and returns a vector<string> containing all the ...
And9686's user avatar
  • 85
4 votes
3 answers
2k views

Custom Vector Implementation in C++

I am relearning data structures while trying to implement them on my own while also trying to get better at C++ as although I have knowledge of C, OOP is still non-inituitive to me. In this simple ...
slimmsady's user avatar
0 votes
0 answers
650 views

Finding the Euclidean distance between the vectors of matrix a, and vector b

Here is the problem, Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of size m. You need to find the distance(Euclidean) of the 'b' vector from the rows of the 'a' matrix. Fill the ...
Levon Avetisyan's user avatar
2 votes
2 answers
599 views

Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
mTvare's user avatar
  • 139
3 votes
1 answer
812 views

Inserting multiple elements at known locations in a vector

Goal In the vector x, I would like to insert the elements of the vector values at indices stored in vector ...
Remi.b's user avatar
  • 617
5 votes
2 answers
471 views

Compressing a vector into a specific range

I want to solve the following task --- I am given a vector of integers. I want to 'compress' this list, where the elements will be replaced with numbers 0 through <...
Mike Smith's user avatar
4 votes
4 answers
1k views

Given two vectors of ints, determine whether one vector is a prefix of the other

Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, compare the number of elements of the smaller vector. For example, ...
Natalo77's user avatar
  • 209
1 vote
0 answers
69 views

A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
353 views

C - Generic vector library

I'm quite new to C, and I decided to create a generic vector library. Here is the code: ...
xilpex's user avatar
  • 289
1 vote
2 answers
582 views

C ArrayList implementation

I have written a ArrayList class in C and I just wanted some criticism on what I can improve on. Any criticism helps, and I was wondering if there is any better way of doing error handling other than ...
Dagar's user avatar
  • 413
6 votes
2 answers
541 views

re-implementation of std::vector

I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code. I have also published code under github. Here is the link to source code + unit test for most ...
Nethius's user avatar
  • 63
8 votes
3 answers
1k views

C++ Creating custom vector

I am new to C++ and Data structures, so I have started writing a custom vector as a practice. Please provide critique and advice. I know it is quite long, so thank you very much in advance. I just ...
msvetlinova's user avatar
2 votes
1 answer
1k views

std::vector Allocator-Aware Implementation

I've just finally finished implementing std::vector. I'm currently re-implementing whatever I can in the hope to learn more of how data structures works. I tried to ...
SomeoneWithPassion's user avatar
0 votes
1 answer
72 views

Find a sum using just two different digits

The problem statement was pretty easy and I was able to run half of the test cases, but some of the test cases in the end gave me the error of memory limit reached. What can I do here to improve the ...
Martin's user avatar
  • 13
3 votes
2 answers
143 views

Implementing dynamic array without STL

For my game engine that I'm trying to write without using STL I implemented dynamic array class(some kind of std::vector). I would like to know whether this code suits best practices. I'm also not ...
Poseydon's user avatar
0 votes
1 answer
499 views

Vector Implementation C++ using RAII

I have attempted to implement a similar version of the STL Vector; several functions are missing but I'd like a few words of advice on whether I am indeed on the right track or whether I should change ...
PeePeePooPoo's user avatar

1
2 3 4 5
7