blakeembrey / code-problems Goto Github PK
View Code? Open in Web Editor NEWCommon code and interview problems solved in multiple languages
License: MIT License
Common code and interview problems solved in multiple languages
License: MIT License
(In respone to this)
Yes, by topic would be OK. Topics like: math related, working with strings, working with arrays, etc.
The lists don't have to provide links to the sub dirs of the repo. Their purpose is just to provide a general overview of what's inside the repo. Without such an overview, the visitor has to go through the list of sub dirs one-by-one which is not very effective.
So, I think an overview in the README file would make this repo significantly more user friendly.
Given the input [-1], both return 0 as the largest continuous sum of the array, when it clearly is -1 (i.e. the only sum of the array). The problem description contains the solution to this problem.
combineTwoStrings("a", "b", "a")
returns true
instead of false
. Only ba
or ab
should be valid for str3
.
$ npm test
...
3 failing
...
1) stackMachine should return the top number from the stack:
AssertionError: -1 == 0
Input: 0
2) stackMachine should multiply two numbers from the top of the stack:
AssertionError: -1 == 0
Input: 01*
3) stackMachine should return -1 when 12-bit stack-machine overflows:
AssertionError: 4096 == -1
Input: 88*1+97**1+
...
npm ERR! weird error 3
...
For the last error, it's helpful to note that 212 = 4096.
The input it fails on is equivalent to 4095 + 1 = 4096.
If you give 1243 the method returns 1423. But it should be 1324.
Dear all,
I was curious to look at the last updates in RNA sequencing. I have seen that https://github.com/adamjamesreid/Plasmodium-single-cell-RNA-seq has already R codes in it. I have adjust it a little because it doesn't work with the new version of R.
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install("scater")
library(scater, quietly = TRUE)
options(stringsAsFactors = FALSE)
molecules <- read.table("PbM_counts.txt", sep = "\t", header = TRUE, row.names=1)
molecules[1:5, 1:3]
anno <- read.table("PbM_meta.txt", sep = "\t", header=TRUE)
genes <- read.table("berg.desc", header=FALSE, row.names=1, quote = "", sep="\t")
pheno_data <- new("AnnotatedDataFrame", anno)
rownames(pheno_data) <- pheno_data$sample_id
PbM <- SingleCellExperiment(assays = list(counts = as.matrix(molecules)),
colData = anno)
keep_feature <- rowSums(counts(PbM) > 0) > 0
PbM <- PbM[keep_feature, ]
PbM <- scater::calculateQCMetrics(PbM)
filter_by_total_counts <- (PbM$total_counts > 25000)
table(filter_by_total_counts)
filter_by_expr_features <- (PbM$total_features > 1000)
table(filter_by_expr_features)
PbM$is_control <- anno$is_control
filter_by_control <- (PbM$is_control == TRUE)
table(filter_by_control)
PbM$use <- (
filter_by_expr_features &
# sufficient molecules counted
filter_by_total_counts &
# controls shouldn't be used in downstream analysis
!PbM$is_control
)
table(PbM$use)
#############################################################
#if (!requireNamespace("BiocManager", quietly=TRUE))
#install.packages("BiocManager")
#BiocManager::install("ballgown")
#library(ballgown)
filter_genes <- apply(counts(PbM[ , pData(PbM)$use]), 1, function(x) length(x[x >= 10]) >= 5)
table(filter_genes)
fData(PbM)$use <- filter_genes
dim(PbM[fData(PbM)$use, pData(PbM)$use])
PbM.qc <- PbM[fData(PbM)$use, pData(PbM)$use]
qclust <- scran::quickCluster(PbM.qc, min.size = 30)
PbM.qc <- scran::computeSumFactors(PbM.qc, sizes = 20, clusters = qclust, positive=TRUE)
PbM.qc <- scater::normalize(PbM.qc)
scater::plotPCA(PbM.qc,
colour_by = "consensus",
size_by = "total_features",
exprs_values = "exprs")
plotPCA(PbM.qc, colour_by="PBANKA_0515000", exprs_values = "exprs", ncomponents=2)
In the part PbM$use I get the error "Error in [[<-
(*tmp*
, name, value = logical(0)) :
0 elements in value to replace 188 elements" . Could you help me?
When working on #60, a C++11 implementation of stack, the existing C implementation #50 already "laid claim" to the stack.h filename, so I chose to use the less idiomatic stack.hpp instead. Since C++11 isn't backward compatible with C++98, if somebody were to add an implementation in that, they'd have to use yet another extension, such as stack.hxx, stack.hh, or stack.h++.
The current organization structure probably won't scale well as more language implementations are added. For now, which files correspond to which language is fairly obvious. But as more files are added, this won't remain so clear. With multiple file solutions (which are idiomatic in some languages), the problem directories will end up fairly cluttered.
I propose individual directories within each problem for each language. The issue could also be partially solved with filename conventions, but in my opinion, that isn't self-documenting or clean. Thoughts?
I think this is a decent resource, but haven't had time to contribute or make it more useful in a couple of years. If anyone would like to help maintain and find a roadmap to improve the challenges and/or solutions, just post here. Cheers!
https://github.com/blakeembrey/code-problems/blob/master/array-pair-sum/array-pair-sum.js#L10
for (var i = 0; i < (hash[k - number] || 0); i++) {
can be simplified as
for (var i = 0; i < hash[k - number]; i++) {
Use Python
to solve the Balanced Brackets problem
I learned binary-search-tree.js today. I found a duplicate code which is very obvious.
https://github.com/blakeembrey/code-problems/blob/master/solutions/javascript/binary-search-tree.js
if we refactored in this way:
doSubNode = function(direct, num) {
if (this[direct] === undefined) {
this[direct] = createNode(num);
} else {
this[direct].add(num);
}
};
and used it in:
...
if (num < this.value) {
doSubNode.apply(this,["left", num]);
} else if (num > this.value) {
doSubNode.apply(this,["right", num]);
}
...
So is any reason to use the duplicated code? or it's OK to refactor the code?
The assumption made while coding is: 1st string will be smallest but i believe that wont be the case.
So we need to find the smallest string(in terms of length).
I have done something similar here:
https://github.com/Akhilj786/Algorithms/blob/master/src/DynamicProgram/LongestCommonPrefix.java#L11-L17
I made a heap ADT, and implemented heap sort and insertion sort and computed the run times
https://github.com/zerolinux5/HeapSort-InsertionSort
TDD is something I have to take a deeper look, but the tests at least for python are broken. It failed because the test can't find the methods used, which is normal because they aren't imported.
python largest-continuous-sum.py
E
======================================================================
ERROR: test_largest_continuous_sum (__main__.LargestContinousSequenceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "largest-continuous-sum.py", line 5, in test_largest_continuous_sum
sum = largest_continuous_sum([1, 2, 3, 4])
NameError: global name 'largest_continuous_sum' is not defined
----------------------------------------------------------------------
Ran 1 test in 0.000s
As this is not a package, how we should accomplish this?
there is nothing in merge-sort.js file
I run the npm test
The error message is following:
solutions\javascript\largest-palindrome.js: line 2, col 3, 'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 2, col 41, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 4, col 8, 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 6, col 19, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 10, col 14, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 14, col 3, 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 14, col 19, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 16, col 8, 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 17, col 5, 'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 17, col 25, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 20, col 7, 'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
solutions\javascript\largest-palindrome.js: line 20, col 48, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 23, col 28, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 28, col 17, Missing semicolon.
solutions\javascript\largest-palindrome.js: line 29, col 2, Missing semicolon.
it seems that largest-palindrome.js use ES6 syntax and jshint did not support ES6 syntax by default.
I prefer such a naming scheme, because it allows you to put several files in the same folder without mixing them up. Plus, editor tabs get better titles.
combineTwoStrings("aab", "aac","aacaab")
should return true
, but returns false
because the function only looks ahead one character. This could be solved with a recursive function call to do the checks for both strings.
I believe the question is to check whether it is BST(Binary Search Tree) or not?? And not construct a BST.
https://github.com/Akhilj786/Algorithms/blob/master/src/Trees/TreeCheck.java#L25-L35
https://github.com/blakeembrey/code-problems/tree/master/find-missing-element @blakeembrey
var findMissingElement = function (a, b) {
return a.reduce(function(x,y){return x+y}) - b.reduce(function(x,y){return x+y});
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.