Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [comparative-review]

This tag is used for questions which present a problem and multiple solutions, where the asker wishes to know which solution is best (and why).

2
votes
1answer
12 views

Showing a “back-to-top”-button after scrolling a certain amount

I have a "back to top"-button on the page, It should be visible after the user has scrolled a certain amount*. This means I have to add or remove a class active ...
4
votes
1answer
68 views

Two ways of implementing a combat system

Below is a segment of a game I am writing to stay in practice with my Java. EDIT The class this method is in is the Encounter class. This class just manages the encounter between the player and an ...
3
votes
1answer
43 views

Optimizing Luhn check digit algorithm

The internet as a whole and Code Review in special already provide a decent amount of implementations of the Luhn check digit algorithm. They often follow a relatively "naive" strategy, in that they ...
0
votes
0answers
43 views

Merge Two Sorted Lists in JavaScript

The task is taken from LeetCode Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. ...
2
votes
1answer
46 views

Populating dropdown lists, using SQL vs. using expression trees and reflection

I'm working with a large enterprise SQL Server database with dozens of tables that are used mainly as lookups to populate dropdown lists, etc. These tables all follow the convention of having (table)...
5
votes
0answers
76 views

Java multithreading many readers one writer implementations

I have a shared data object with writer threads and reader threads. Number of threads can read from the shared data at the same time (in the code getmethod), and ...
2
votes
1answer
50 views

Length of the longest consecutive run of 1s in its binary representation

The task Given an integer n, return the length of the longest consecutive run of 1s in its binary representation. For example, given 156, you should return 3 My function solution 1 Style 1 ...
0
votes
1answer
31 views

Filling in the card expiry date from transaction data

I'm integrating my app with a payment gateway, and have the following code which returns an array to populate the transaction info: ...
2
votes
2answers
65 views

Python program for Jump game II

This is a Leetcode problem: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length ...
-3
votes
3answers
125 views

Python program to find the first missing positive integer in a list

This is a Leetcode problem: Given an unsorted integer array, find the smallest missing positive integer. Note: Your algorithm should run in O(n) time and uses constant extra space. ...
7
votes
1answer
178 views

Usage of TPL vs Parallel.ForEach() on file processing

i've been working on an implementation of a my own from scratch set of library Astron and I wanted to get my TPL usage reviewed because i'm not confident with this technology :/ My app is currently ...
3
votes
1answer
78 views

API for multiple printer attributes [closed]

I have network printers which have different attributes (e.g. supported network protocols, languages, status, print modes). ...
4
votes
2answers
78 views

Create a min stack

The task is taken from leetcode Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes ...
3
votes
3answers
46 views

Counting duration values

I have a durations as such: [{'duration': 3600}, {'duration': 3600}] And I want the output to be ...
5
votes
1answer
77 views

Container with most water

The task is taken from leetcode Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of ...
4
votes
1answer
157 views

Return all valid paren strings with a given length

The problem is Given a non-negative integer n, return all valid parentheses strings with n open parens and ...
6
votes
5answers
563 views

Checks user level and limit the data before saving it to mongoDB

I have a function that checks user level and limits the data before saving it to mongoDB database (pre 'save' middleware for mongoose). It have been getting complexity warnings and tried to rewrite it,...
7
votes
3answers
1k views

malloc in main() or malloc in another function: allocating memory for a struct and its members

When initializing a struct in C, we can allocate memory inside the main function or within another function and return a pointer to the newly created struct. This ...
1
vote
1answer
64 views

Simple MySql or MySqli Class

Which one of these methods is better/safer to use? And what benefits could I get using one or other? Simple mysqli: connection.php ...
4
votes
1answer
44 views

Comparing 2 iOS and Android versions

Please review and let me know which version is better. I'm just trying to find any caveats or better ways to accomplish the a version comparison independent from Android and iOS. Formats accepted: '1....
1
vote
1answer
93 views

Given a list and a number k return whether any two numbers from the list add up to k

The task: Given a list of numbers and a number k, return whether any two numbers from the list add up to k. For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. ...
1
vote
1answer
43 views

Clone Vector in rust except at one index [closed]

Let's consider you want to clone all items of a vector orig except the item of index i should be taken from alternative value <...
5
votes
1answer
68 views

Two cross-platform implementations of getline in C

I created my cross-platform implementations of getline function in C. It takes different arguments and have different return values than 'original' ...
1
vote
0answers
58 views

No performance gain with SIMD 3D vector for ray tracer

I wrote two versions of vector class for my ray tracer. Non-SIMD version and SIMD version. You can find the code below. I want to ask what things should I keep in mind to get max performance with SIMD....
3
votes
0answers
78 views

A Node and a Socket, template or inheritance? [closed]

I'm trying to create a node based scripting/computation system. I've come up with 2 solution that seems to work. One involves template, the other one inheritance. Basically what I want to achieve is: ...
0
votes
1answer
57 views

Formatting milliseconds as days, hours, minutes, and seconds [closed]

This is a function which aims to convert an amount of milliseconds to a more human-interpretable Day(s) Hour(s) Minute(s) Second(s) format: ...
0
votes
0answers
64 views

Kadane's algorithms to leetcode “121 Best Time to Buy and Sell Stock”

I employed the conventional Kadane's algorithms to solve a maximum subarray problem in leetcode Best Time to Buy and Sell Stock - LeetCode Best Time to Buy and Sell Stock Say you have ...
3
votes
1answer
57 views

4 solutions to leetcode 202. Happy Number have almost same performance

I am working on an easy math question Happy number Happy Number - LeetCode Happy Number Write an algorithm to determine if a number is "happy". A happy number is a number defined by ...
3
votes
0answers
28 views

Two solutions to leetcode 127.wordLadder

I am working on Word Ladder - LeetCode Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such ...
4
votes
1answer
81 views

Time(n) Complexity of Fibonacci Algorithms

It is my first use of classes in Python. I wanted to create something useful and try some new things as I learn this cool language: strategy pattern, testing with nanoseconds precision, curve/poly ...
0
votes
0answers
53 views

Median of three partitioning taking more time than standard quicksort in java

I implemented a standard quicksort and I have a project where I need to improve it. I am trying to make quicksort faster by implementing median of 3 partitioning. I copied codes from trusted ...
1
vote
0answers
44 views

Median of 3 partitioning taking more time than quicksort in java

I have a quicksort code in java which I want to improve. The improved code should take less time than the quicksort code. However when using my improved code which implement median of 3 partitioning, ...
1
vote
0answers
50 views

Rails dynamically changing parts of view but using the same method in controller

I have this update method which decides whether to update or recreate(same as update but resets the approval_status and create_date) of the building_approval object. I have the on_progress? method on ...
5
votes
3answers
85 views

Getting device type from user agent in Python - is explicit better than implicit? [closed]

I'm debating with my colleagues which code is better: user_agent is a class instance. The class itself comes from a third-party library so we don't have any control ...
2
votes
2answers
80 views

Toggle Function in JavaScript

Here is my current toggle function: ...
-2
votes
1answer
50 views

Functional vs non functional approach in python [closed]

This is not a task, but I want to know what the general consensus is on functional programming. Particularly functional programming in Python. The two snippets of code I am comparing are the ...
1
vote
1answer
62 views

Comparison functions for 2D points [closed]

I have the following class for 2D points: ...
2
votes
2answers
109 views

Formatting a price in Swift using an extension vs. a class

I have a price as a Double, which I should format it as a String. Should I use an extension instead of classical class to ...
7
votes
3answers
185 views

Leetcode 38: The “count-and-say” sequence

38. Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: ...
4
votes
1answer
124 views

Object-Oriented Breadth-First Search Implementation

My goal is to write a GUI application where a user can create a maze and select an algorithm. The passage of the algorithm from a selected start and end point should be visualized. The following ...
1
vote
1answer
45 views

Making EmployeeHistory ViewModel immutable as code analysis suggested

I want to display on a view the EmployeeHistory view model sorted by elements.assignEffDateNext and I want to instantiate and ...
4
votes
3answers
181 views

Uniformly generate a number from 0 to n-1 that isn't on a blacklist

The task: Given an integer n and a list of integers l, write a function that randomly generates a number from 0 to n-1 that isn't in l (uniform). Solution 1: ...
3
votes
0answers
55 views

Export EXIF data from thousands of images to CSV

I have written a script that retrieves specific fields of Exif data from thousands of images in a directory (including subdirectories) and saves the info to a csv file: ...
1
vote
1answer
92 views

Find out whether string A can be shifted to get string B

The task: Given two strings A and B, return whether or not A can be shifted some number of times to get B. For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, ...
-3
votes
1answer
69 views

About the problem of seeking matrix inverse

Recently I have solved the inverse matrix in three ways, found that their work efficiency has obvious differences. This is the case: ...
3
votes
5answers
557 views

Finding Isogram Word

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times. The ...
8
votes
4answers
2k views

Reversing a string - two approaches

Test Case: Input- "I'm hungry!" Output- "!yrgnuh m'I" Approach 1: In this approach, I used a empty string and bind it with the input string reversely. ...
3
votes
0answers
37 views

Basic Qt5 UI with button [closed]

I have the following Qt class: mainwindow.h class MainWindow : public QWidget { Q_OBJECT QPushButton* m_button; public: explicit MainWindow(); }; mainwindow....
1
vote
0answers
43 views

Closest 3Sum in Scala

This question is taken from Leet code. Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three ...
5
votes
1answer
44 views

Mouse control of a camera in an OpenGL program

Introduction I'm doing an OpenGL program in C. As of now I'm working on the 3D camera system and got the control right. Now I'm working on the mouse control. It works, but I have used two different ...