instruction stringlengths 71 71.9k |
|---|
I'm learning RxJava and this is what I attempted to find the mean of 'n' transactions.
List<Transaction> transactions = TransactionsStore.getTransactions();
BigDecimal nTransactions = new BigDecimal(transactions.size());
Observable.from(transactions)
.map(transaction -> transaction.amount)
.reduce(BigDe... |
I just got rejected at the tech interview of a job application. They gave me the following exercise for me to complete:
They gave me a binary file with 10 million pairs of 16-bit signed integers. From those 10 million, I had to find the 10 closest points to (-200, 300) and the 20 furthest points to (1000, 25).
I finish... |
I've been given this little test exercise for an interview as php developer, and I'd like to hear from you if my solution is good (enough) or if the problem could have been solved in a better way. Please keep in mind that I've no academic training in CS or equivalent (rather the opposite) and my career started as a sel... |
I have this Java class for building bit strings. The set of methods it provides resembles that of java.lang.StringBuilder.
See what I have:
BitStringBuilder.java:
package net.coderodde.util;
import java.util.BitSet;
/**
* This class implements a simple bit string builder.
*
* @author Rodion "rodde" Efremov
* @ve... |
I often find myself implementing IComparable{T} in different classes for sorting in a very similar fashion:
Values meeting criteria X and Y should be sorted to the front
Values meeting criteria Z and W should be sorted to the back
Values not meeting any special criteria can stay where they are
So, I've created a cla... |
I wrote a script for reading a CSV, parsing it and saving data to MongoDB. I would love some input on how I'm handling errors and dealing with callbacks. I wrote it with nested without using async and the nesting wasn't too bad, but I tried this way thinking it might be better practice. It's a one-off script.
var fs = ... |
This is to be used like an Enum (as parameter mostly), but for string
(Using .NET 3.5)
Actual implementation:
Public MustInherit Class StringEnum(Of T As {New, StringEnum(Of T)})
Private Shared ReadOnly _lock As New Object
Private Shared ReadOnly _cache As New Dictionary(Of String, T)
Private _value As Str... |
This is an update to my previous post about my Active Directory Query Application. I have made multiple modifications, and I request some feedback.
Summary: This program queries an active directory and writes either a list of the users or a list of the users with a list of the groups each user belongs to. The search is... |
public abstract class Element
{
// Removed for verbosity ...
protected abstract byte[] GetBytes();
}
I'm attempting to create an engine that can create a document in a very specific format. The document itself is composed of various elements, and each element has a very specific binary representation.
I origi... |
This is some code to generate a histogram (or maybe: histochart) in the form of a simple list of words and how many of that word were found in the input file. It accepts an input file name on the command line. For our purpose, a "word" consists of English letters and/or the apostrophe (e.g., so we're is treated as one ... |
I wonder if there could be a faster palindrome checker in Java. The best one I have is O(n/2) which is O(n) eventually:
public static boolean isPalindromeNaive(String s) {
StringBuilder sb = new StringBuilder(s);
StringBuilder sbReverse = sb.reverse();
if (s.equals(String.valueOf(sbReverse)))... |
I have written a piece of VBA code to essentially replace a complex formula that I was using in the Excel cells.
I have the data on Sheet2, which describes multiple train journey's along the same track. the data is set out with each train journey after each other in an order of start time. The data consists of the tra... |
I decided to use Java TreeMap because it seems like a great data structure to fit this problem. However, I am not sure if there could be much simpler methods using better data structure or how I could start improving the time complexity of this algorithm. I would also like to know how I can improve the style of the cur... |
What I'm doing:
Searching in current directory for a set of files.
Filtering the set.
Searching through the filtered set of files for a specific line sequence.
Write to an output file that line along with the line that directly preceded it and the file in which it is found.
There's no actual purpose to this besides p... |
How do you list your referenced solution assemblies for IoC registration? I was really tired of typing something strange as new [] { typeof(SomeType).Assembly, … }. What do you think about the following approach?
Use case:
class Program
{
static void Main(string[] args)
{
foreach (var a in Solution.Asse... |
I want to write an automated bash script for installing Ruby and Rails using rbenv, but I am getting session reload issues in the terminal.
#!/bin/bash
echo "Installing rbenv.."
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'expo... |
I need to remove all the numbers appearing inside square braces such as [9] , [2] , ....
This is my regex:
"(?:\[\d*\])"
Which is working fine.
But I am totally new to regex so let me know if is there a better regex that can be used.
Try Online
|
I have been learning JS (mostly using D3) and I wanted to put the Module Design Pattern to use. I wrote a simple script that lets you build a bar chart with more ease / readable code.
The end user code:
canvas.initialise()
canvas.margin(20, 100, 60, 20)
canvas.width(500)
canvas.height(400)
canvas.finalise()
svg = canv... |
For certain modules or functions, I want to have a different format for the logged messages. I have done this in a way that looks a bit hacky: I have set a special Logger, containing a special Handler, that has the right Formatter.
Here is a simplified portion of my configuration file:
formatters:
dbgMessageFormatt... |
I am validating a form using jQuery.
It is working perfectly, but I just feel the code is quite "bulky". There is a lot of if statements being used to achieve this logic in the app.sendForm.init() function. I think this could be tidied and any advice here would be greatly appreciated. Perhaps I should be using a switc... |
I wrote a small routines to create a mirror for any binary tree. I am just sharing my necessary routines instead of full class. could you please let me know your comments on this. I just curious to find the complexity of this but I am new to algorithms.
void tree_sample::mirror_image()
{
create_mirror_for_left_subt... |
After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing.
I have written a generic unit test class for equals, hashcode and comparable that will test every contract of each function.
I've attached the generi... |
This is the continuation of a previous question I posted here.
I've improved (at least I think so) the initial script from the previous question, now storing the data in an array, it runs slightly better, but still sometimes there's some lag in safari. I've tried to call requestAnimationFrame on scroll and cancelAnimat... |
I have two very similar methods, which make HTTP requests, the difference is that one makes PUT and another GET. Is there any proper Ruby way not to repeat the setup code and not to pass the flag parameter?
def notify_client(url, params)
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl... |
Currently, I am using an algorithm that finds the best move based on the existing states of the board. Is there a better way to do it? Is there a data structure that I can use?
I have also considered the MinMax algorithm, but did not want to use it as it checks for every possibility on every turn.
var playerSym;
var c... |
I have 4 tables, filled with some example data
user table
id | name | idAddress |
------------------------
1 | Bernd | 1 |
2 | Max | 2 |
3 | Tom | 3 |
4 | Bob | 4 |
5 | Alice | 5 |
address
id | country | zip |
----------------------
1 | DE | 39213 |
2 | CH... |
i've just started to learn python /django ..
im coming from php world ...i mostly struggle with None values which are new to me .. in php i mostly did my boll checking with true/false but in python None is favored .. .also collections (list , dictionary) are different here but javascript has prepped me for that !
anyw... |
I'm currently learning C with K&R, i'm right now in the exercise 1-22, but it's a little... hard to understand (at least for me). It says:
Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program doe... |
After reading the book from which this example is from I started using APIs like this
typedef struct stack {
char **items;
int len;
} stack;
stack *stack_new() {
stack *out = malloc(sizeof(stack));
//initialize the struct
*out = (stack) {};
return out;
}
void add(stack *in, char *val) {
... |
L-systems are basically rules for recursively rewriting a string, which can be used to characterize e.g. some fractal and plant growth.
I wrote a small class to represent deterministic L-systems and used it for two examples. Any comments would be greatly appreciated, especially about the class design, the structure of ... |
I have written a small program which has 2 main classes :
ServerSideMMS: This can access the SharePoint Managed Metadata Services, but only from the server which is running SharePoint
ClientSideMMS: This can access the SharePoint Managed Metadata Services from any client machine
These can both be used to access MMS ... |
I have a polymorphic notification model. When user gets a notification he can get on the page of the notifiable to check out what happened exactly. For instance invited you to join product or commented on a post. On the top of this I also have a polymorphic comment model. So user can get a notification not only for co... |
I made a simple Pong game using SDL2, with a twist: You don't get to play :), only the 2 AIs get to. ;)
Because Pong is a very small game, I put everything in a single file (main.cpp). If that was the wrong choice, please tell me :).
I know that global variables are bad, but in my defense they are all constexpr (if th... |
I use this code to check that all files in a directory are free from Unicode and non-printable characters.
Can I improve the structure of the code?
#!/usr/bin/env python3
import argparse
import os
import string
import sys
def main(input_folder):
for directory, subdirs, files in os.walk(input_folder):
for ... |
I am working on a calendar widget for a project. For any given date, I need to build a 2D array representing the "Month" that the date falls in, where the rows represent weeks in the month and the cells in those rows are individual days. The weeks must start on Monday, and if the month does not start on a Monday, it mu... |
I'm remaking an old program of mine in Clojure. It involves "Beings" (generic entities capable of attacking and breeding) let loose in a confined space.
I've noticed a pattern of taking a record, creating a modified version of one of its fields, then "overwriting" the field.
It generally seems to look like:
(defn map-p... |
This works but feels clunky - any suggestions for improvement?
public static <T extends View> T findViewByClassReference(View rootView, Class<T> classReference){
if(classReference.isInstance(rootView)){
return classReference.cast(rootView);
}
if(rootView instanceof ViewGroup){
ViewGroup viewGroup = (ViewG... |
Given a list of sell offers and a list of buy offers for an item I want to determine how many units to trade for maximum profit.
Each offer consists of a price and a maximum amount of units being traded. Offers can be partially fulfilled (i.e. if a buyer/seller wants to trade 100 units, it's ok to trade only 10). Howev... |
I'm teaching myself Python and when a friend posted this sentence
Only the fool would take trouble to verify that his sentence was
composed of ten a's, three b's, four c's, four d's, forty-six e's,
sixteen f's, four g's, thirteen h's, fifteen i's, two k's, nine l's,
four m's, twenty-five n's, twenty-four o's, fi... |
Here's my code and I want to know if there's a better method for doing so. While the question has stated two stacks I wonder if we could do only with one as well?
/**
* Created by mona on 5/26/16.
*/
import java.util.Stack;
//Implement queue using two stacks
public class QueueViaStacks {
private int size=0;
... |
I have implemented an algorithm which computes a maximum clique via a heuristic. The pseudo-code can be found in this Paper (see Algorithm 2).
Maximum Clique Problem
Given an undirected, simple Graph \$G=(V,E)\$, a clique \$C \subseteq V\$ is a subset of vertices such that all vertices in \$C\$ are
connected, i.e. \... |
This is an application I wrote that allows multiple TCP clients to share a single TCP connection to a remote server (hosted project, and a demo). Traffic generated by the server is forwarded to all clients. Traffic generated from any client is forwarded to the server. I don't concern the case where client traffics are ... |
I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns.
/**
* Created by mona on 5/26/16.
*/
import java.util.Arrays;
import java.util.Stack;
import java.util.HashSet;
public class EvaluateRe... |
So I have written the following code and it works for various same length isomorphic strings I have tried. However I am not sure what are some time complexity improvements and coding tweaks that could be applied to the code:
/**
* Created by mona on 5/26/16.
*/
import java.util.List;
import java.util.Map;
import java... |
I'm a beginner at Lua and programming in general and I just made a simple calculator and I was wondering where I could make improvements.
print("Choose numbers:")
print("Num1:")
local num1 = io.read()
print("num2:")
local num2 = io.read()
print("Choose operator: + / - / * / /")
local operator = io.read()
if operator ==... |
Pretty new to this hence taking it as challenge. I have a master sheet in which Column A have all the file names( complete file name with .xls extensions). I need to copy data of column b in this sheet and paste it in all the files in a particular folder in a particular tab. There can be multiple items for one name. Sa... |
So I was asked this in an interview, and I had to write this code on a white board. Sadly I couldn't complete the code :( .
I've realized that writing code on white board is completely different from typing it on an editor. Firstly because, I type way faster than I write and secondly I can't keep adding lines in betwe... |
I am currently working on a small internal rating system for clients to be able to prioritise my work based on what client pays best. The input data is the hourly rate they are paying and based on that they should be divided into categories in are the range from A-D. The first setup looks like this:
def category_for(cl... |
I'm trying to use a different method to calculate a blob area from contourArea, using the countNonZero function. I want to see if there is significant approximation introduced by contourArea function, and also be able to calculate area of contour with auto-intersection.
cv::findContours(drawingIn, contoursIn, CV_RETR_T... |
i recently wrote my first custom config section. I have a collection of index files, each has a path and a savetime:
internal class searchConfigSection : ConfigurationSection
{
static ConfigurationProperty s_indexCollection;
static ConfigurationPropertyCollection s_propertyCollection;
static openSearchCon... |
I've written a naive shortcode parser in JS that parses shortcodes akin to those found in Wordpress. The intention is for this to be used in realtime on the client in order to preview edits on the fly.
Excusing the strictness of the regular expressions I'd be interested to find about my implementation's:
Performance ... |
My goal is to implement a simple pomodoro timer using Go: channels, goroutines.
I'm a newbie in Go world and have some misunderstanding about naming convention. I read a lot of Docker's code on GitHub and there I saw that people sometimes use very short names. These names are not clear for me (a man who comes from C++ ... |
The code below is a simple coding exercise I got from a book that asks to remove the duplicates from a single-linked list (using a simple struct; this is part 2, see part 1 here).
Question 1: Is there a better way to delete a Node than by creating a temporary variable temp and deleting that. I actually tried deleting ... |
I made my own class that inherits from button and has an OnHold event. It seems to work ok but I'm wondering if I can improve it or if you can spot any glaring mistakes that I made.
Here is the code:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
[AddComponentMenu("UI... |
I created an automatic upload tool, which is working great (most of the time). As I want to improve the code I have several questions:
Is it possible to make the iexplorer process smoother? I don't like it that people can see the "sendkeys" actions. Is there possibly way to run the process in the background/lay a pict... |
The code takes srcPaths and actionType as parameters. The former is a string with tab-delimited file paths, while the latter is a string that may have values of "Lock", "Unlock", and "Toggle", which is chosen by the user.
#!/usr/bin/python
import os
import sys
import ntpath
import subprocess
srcPaths = sys.argv[1]
ac... |
I have written a custom method to use StringBuilder in java. My Requirement is to create a method which accepts any number of arguments of any type and return String by concatenating the arguments.
eg. msgBuilder("Hello ",0," how"," are"," you ",2.5) return "Hello 0 how are you 2.5"
Here is my java code. Please Someone... |
I have a switch statement used to handle options that a user selected (stored in an array). The array is iterated through, and for each element (enum object) in the array, an appropriate action is performed. However, the enum has over 50 items, so the switch statement is very long.
The items are all necessary and relat... |
def sort[A, B: Ordering](data: List[A], desc: Boolean)(measure: A => B): List[A] = {
val baseOrdering = Ordering.by(measure)
val ordering = if (desc) baseOrdering.reverse else baseOrdering
data.sorted(ordering)
}
private def sortOne(stats: List[One], by: String, desc: Boolean): List[O... |
I'm trying to find a way to handle decimals in mongodb. Is there any good way and/or should I handle it with a class like this:
using System;
public class MongoDecimal
{
public long Value { get; set; }
public long SubValue { get; set; }
public long SubValueToValue { get; set; }
public decimal ToDecima... |
Should I check Count before Linq Single() call if I expect only one element?
if (objects.Count != 1)
{
throw new
InvalidOperationException(
"%Collection% should contain one %element%, but now it's: "
+ objects.Count);
}
return objects.Single();
Single implements the sa... |
Here is my current schema:
Brand:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var BrandSchema = new mongoose.Schema({
name: { type: String, lowercase: true , unique: true, required: true },
photo: { type: String , trim: true},
email: { type: String , lowercase: true},
year: { type: Numbe... |
I am writing a c# console app that will take a user input from a list of selected options and do things based on the selected option. I have it working right now but just looking over it there seems that I should be able to shorten the code with other methods and make it perform a bit faster and more efficient but for ... |
I built a random password generator in Java which is meant to be run from the command line. It accepts options for:
Length
Upper case letters
Lower case letters
Special characters
Numbers
The project is on BitBucket.
Example program execution :
java -jar program.jar -length 12 -number -upper -lower -special
This ge... |
I've been tasked with finding property differences in massive JSON structures and returning them in a particular fashion (i.e. [key_1.key_2, key_1, etc.]).
Here's my code, which is focused on readability so some redundant decorators are used (they will be removed). I am looking for any performance/logical problems with... |
My first Code Review post.
I'm up to a generic implementation of the A* search algorithm in Swift (for now, it's a single goal implementation).
Here's what's been coded so far:
// State : a protocole for states in the search space
protocol State : Equatable {
// successors() : returns an array of successors states... |
I have a cryptographic function with two 24 bit keys.
I have two blocks of input and two blocks of output, and want to brute force the keys using CUDA.
Overview:
The function is composed to two back-to-back 3 round substitution-permutation-networks with block size of 24 bits and sbox size of 4 bits.
Due to the low bl... |
I am writing a program that can implement algorithms to solve the TSP. My goals:
The solver can record every algorithm step, so that the whole solving process can be later visualised by charts or animations
It's easy to add new algorithm implementation
End user has full control over the simulation parameters
I tried ... |
I wrote some code to solve this problem https://www.hackerrank.com/challenges/string-o-permute which basically states: take an even length string and swap all the even indexed characters. For example the string "abcd" should become "badc". I'm looking for a general code review as I'm very new to F# and specifically I'd... |
I've created a basic cipher program that will turn your string into a Rot13 cipher. I'm pretty sure there are much easier ways to do this, so a little input on what I've done would be great:
What did I do well?
What can be done better?
Are there easier ways to do this?
using System;
namespace Rot13
{
class Ceas... |
I'm teaching myself Rust, and to do this I've written a toy register based virtual machine. I hope the code is easy to follow - I just want to know if there are any mistakes I am making with the language philosophy or if there are syntax tricks I could be using. For example, the program counter pc and the register fiel... |
Continuing the series of Code Explorer posts, here is the collection of view models for the tree nodes:
This is the interface for nodes with a declaration.
public interface ICodeExplorerDeclarationViewModel
{
Declaration Declaration { get; }
}
And here is the abstract view model they are all based on:
public abst... |
I have a component that I've used myself for quite some time, the short story is that it automagically implements a property change notification mechanism (very useful for implementing INotifyPropertyChanged for example, but can be useful in other ways as well).
There are other solutions available which use a similar t... |
This is my very first application written in Java and so I finalized it, solely because it occurred to be my thesis.
It is a very simple program that lists categories (Northwind database is used as a template db) and as you one-click one it lists ID, Name and Price of all the products in this category in a table.
dbu... |
The site should be accessible only to signed-in users. I'm making sure I publish and enable data manipulation to only those, but I wanna make sure even the app structure won't be visible.
What I did was creating an autorun that checks for changes in signed-in user and reloads the router. The router takes care of redire... |
I have written a program in x86 assembly (Intel syntax/MASM) that interprets brainfuck code that is fed to it via an interactive console and prints the final stack to stdout. Note that it does not include an implementation for the , command, but everything else has been implemented. The idea is that it presents the use... |
I have written a CSV parser to read in 12609000 lines of CSV data. Each line has 16 fields of both string and double type data. The following code takes about 40 seconds to parse the data. I would like to know if there is a better way of doing this which can make it even faster. I have seen recommendations to load all ... |
I have created a UI shown in the screenshot. I am initalizing too many JPanels within a panel in my code to achieve the UI which will lead to bad code design and slower performance.
Is there any good practices to follow in writing such a UI?
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Grid... |
Assuming everything else works as expected, is the following a correct - but not the most efficient way - of implementing Dijkstra algorithm? Because I have tested it on several examples and it gives correct result. But I can't imagine Dijkstra is that simple.
public static void FindShortestPath(Node source, Directed... |
Summary: Is my server handling every error and corner case possible? If not, what did I miss?
Details
I'm trying to write the most basic socket server I can, so I can learn TCP and the pitfalls of parsing network data. I'm also worried about security (DDOS mitigation) and making sure the server never panics (unless it ... |
Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the majority element in an array?
/**
* Created by mona on 5/27/16.
*/
import java.util.Arrays;
public class FinaMajority {
public static int findMajority(int... |
I have written a simple JS module "loader" (loader is in quotes because it doesn't actually load the files) that is designed to resolve simple dependencies between modules. It is heavily inspired by module.js and takes some of it's design from it.
Here is the code itself:
(function() {
function create() {
var def... |
I wrote the following code for solving the Rod-Cutting Problem using dynamic programming:
Rod Cutting Problem: Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces and also fi... |
This is the first time I'm trying to use promises in JavaScript so I'm not sure if I have done it correctly, but it seems to work. The problem is that I have ended up with a "nested when" and it doesn't look that great. There probably is a nicer solution out there. I would really appreciate some feedback on how I can i... |
I am working on a genetic algorithm using the following code. The variable best in generateNewPopulation stores the best chromosomes from the previous generation and adds it without modification to the new generation. The problem is that if I allow crossover, the "best" changes it value to the best of the current gener... |
I have a list of factories. Each factory has an item of its own and a list of other items from competitors.
I need to sort the list of factories based on price of their items and also sort list of other items from competitors for each factory.
What I am doing require to sort collection of factories and loop through all... |
My task is to code something that prints out this:
This is what I have done so far.
diag matrix = diag2 [] [] matrix where
diag2 [] [] [] = []
diag2 xss [] (zs:zss) = diag2 [] (reverse $ zs:xss) zss
diag2 xss ((y:ys):yss) zss = y : diag2 (ys:xss) yss zs... |
I'm starting with PHP so I can save data to a MySQL database. I read a lot and it seems the "escape" strings is not so safe.
This is my code:
<?php
session_start();
date_default_timezone_set('America/Argentina');
require_once("config/db.php");
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
mysqli_select_db($link, ... |
I created my first java application for a college assignment. I tried my best to design my application using best practices of MVC design patterns. I have read about it on Stack Overflow and other sites. My question basically is: Do I follow the best practices? Every feedback is much appreciated. Below is my code.
View... |
In a txt file there are IDs and next to them there are their neighbours like this:
1 1
1 2
1 3
2 1
2 4
2 8
3 5
Using AVL trees I store the IDs in one AVL tree and for every ID in this AVL
I make another AVL tree in which I store its neighbours.In the end I make another txt file that in every line has an ID , i... |
I have this block of code which clearly looks like duplicate, but I don't know how to refactor.
float offsetDifference;
nfloat newLogoHeight;
nfloat newHeaderHeight;
nfloat newLogoWidth;
if (offset > _previousOffset)
{
offsetDifference = o... |
I'm an elixir beginner. I'm doing the word count exercise of exercism website. The word count exercise returns a map with the word as the key and the number of instances as value. The exercise excludes special characters, and ignores underscores. My code works, but I'm sure there is a way to make it cleaner. I've a... |
A few weeks ago I recall a HackerNews story (found it again: "I Don't Want to Hire You If You Can't Reverse a Binary Tree") about reversing a binary tree (with, as I remember it, the end goal being to test for symmetry by testing the reverse for equality with the original).
I started hacking this implementation up as ... |
I am wondering if my code is needlessly redundant. I noticed, when looking over my code, that I had a unnecessary variable and if statement. Both Fire() methods achieve the desired result without error (from what I have seen). To me, the redundant Fire() method reads a lot nicer and is my preferable method but I'm just... |
I'm looking for input, advice, criticism. This is my first helper class. While use of mailto URLs should most often be trivial, I have a real world need to send to multiple recipients and with a body of text something more than just a one liner. Doing so gets sticky and there are some pitfalls with reserved characters,... |
I've created a project on Khan Academy as part of the Natural Simulations course on random walks.
This project is in JavaScript, using the Processing.JS library, slightly modified by Khan Academy.
(In the main, the inclusion of the Processing.JS library offers a few functions for drawing on a canvas. The majority of my... |
Solution:
public class RemoveDuplicateInString {
public void removeDuplicate(String s){
System.out.println("Before::"+s);
int len = s.length();
for(int i=0;i<len-1;i++){
char c = s.charAt(i);
String preString = s.substring(0,i+1);
String temp = s.substrin... |
(See also Finding shortest paths in a Wikipedia article graph using Java - second attempt.)
I have this sort of a web crawler that asks for two (English) Wikipedia article titles (the source and the target), and proceeds to compute the shortest path between the two:
package net.coderodde.wikipedia.sp;
import com.googl... |
Problem Statement
In a school, chocolate bars have to be distributed to children waiting
in a queue. Each Chocolate bar is rectangular in shape. Consider its
side lengths are integer values.
The distribution procedure is as follows:
If a bar is not square in shape, then the largest possible square piece of Chocol... |
This program prints odd numbers by thread1 and even numbers by thread2 sequentially. Can this code be optimized or made more efficient?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t condition_var = PTHREAD_COND_INITIALIZER;
void *fu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.