instruction
stringlengths
71
71.9k
This finds a value via a stored procedure then runs a second process in the same stored procedure rather than calling a second stored procedure. When a call is 'simple' i.e. not Where x y then... I keep the stored procedure, even when I need to get a variable, in the same procedure. I'd like to see if the concept that ...
The need came up the other day to be able to easily switch back and forth between making IBM DB2 queries and MS SQL queries. I didn't want to mess with NHibernate as I was on a time crunch, and I also didn't want to have a million connection strings. Lastly I learned a while ago that for classes that needed to be used ...
A friend gave this puzzle: Find 3 numbers (say, A B C) such that \$ABC+ABC+ABC = CCC\$ ABC means \$((A*100) + (B*10) + C)\$. Also, these 3 digits must be distinct. I wrote a quick code to find out the answer: int main(void) { // your code goes here int hun,dec,unit; int final_num = 0; int temp_num = 0...
This question is a followup to the last one. I followed RobH's advice and his edge case bug found in my code with this solution: private Line CreateParallelLine(Line target, int offset) { var parallelLine = new Line(); var xDifference = target.point1.x - target.point2.x; var yDifference = target.point1.y ...
Since I'm new to web development, I've decided to create this carousel, to practice a bit of JavaScript, more specifically jQuery. I'm really happy with the result, but I'm sure that to an expert my code would look like a disaster, so I would love if someone could help me make the JavaScript of this slider a bit "prett...
Here is what the reset link looks like that goes in an email to the user: www.webdev702.com/forgotPassword.php?empl_id=121&email=nicholasdarley@gmail.com&request_time=1432183745918&resetCode=MG4L0aBqim27wK9fAWcJ2XCBF There are many parts to the link and they are: empl_id: the id of the person matching the email addr...
In order to avoid boilerplate code and make an extensible pool of actions for the same portion of code (a row of texts to edit), I've prepared this code. var actions = { editName: function () { var curName = this.nameField.text(); this.nameField.data('oldName', curName); this.nameField.ht...
I'm pretty new to client side scripting and I'm still learning. I've written this JS plugin which animates blocks of HTML (fade-in from left/top/right/bottom) as you scroll down the page. Everything seems to be works correctly, but was just wondering if there is anyone who could suggest how I can improve on this... For...
I've written the core functions for a basic 2048 game. I know Python isn't a functional programming language, but I like the "functional style" (easier to maintain, simple to understand, more elegant), and have tried to use this rather than iteration, mutation, etc when I can. From a functional perspective, what more ...
Having read Can you do the maths puzzle for Vietnamese eight-year-olds that has stumped parents and teachers?, which presented the problem of filling in numbers 1 to 9 to satisfy $$ a + 13 \frac{b}{c} + d + 12 e - f - 11 + \frac{g \cdot h}{i} - 10 = 66 $$ … I thought I'd try a Common Lisp implementation as a learning e...
Look at the method setupCamera. I use it to reduce the size of the create method. As you can see, inside this method I instantiate camera and viewport, that are fields. Is there any problem to do that, or exists there any surer way to do that? public class HudCameraSample extends ApplicationAdapter { private sta...
This is really the first full app I've written in JavaScript minus CSS styling which I plan on adding later. Are there any ways it can be improved? Any ways I can make it cleaner or easier to read? "use strict"; // Constructor function for individual parts of game grid square // Each grid square contains a state pro...
I have a method RefreshCustomersInternal that refreshes customer data from a server and returns a Task. Since this process is very costly, I want to prevent this method from being called too many times in a short time or prevent the process from running if there's another refresh process running already. So a wrapper m...
In my Java event bus project, I have a private generic method that retrieves a Set<Subscriber<E>> from a private Map<Class<? extends Event>, Set<Subscriber<? extends Event>>> (the subscriberMap). /** * A map of Event types and Subscriber Sets. * * That is, the Set of Subscribers set to an Event type * is assumed ...
Given this as a the Problem Statement Given two numbers, find the sum of prime numbers between them, both inclusive. Input: The first line contains the number of test cases T. Each test case contains two space separated integers. Output: Print the answer on a new line for each case. Constraints: 1 <= T <= 100 1 <...
I have code which gives permutations for 10 lists. The code works fine for small number of lists with small number of values. Result : It should return all possible permutations. I have to store the permutations instead of directly working on it and discarding. As soon as I try for 10 lists, it errors out with OOM : h...
Original Problem Short Summary: Given a \$M\$ possible characters all of which must be used at least once, find the number of possible combinations of length (exactly) \$N\$. The first input contains the number of cases, followed by pairs of M, N. Output is modulo 1000000007(\$10^9+7\$). Example Input: 4 1 1 ...
Last night I was working on a project that I've embarked upon as a learning exercise. I decided to add a pagination feature to my blog system. I made an attempt at it and got close... but I decided to undo my changes and I searched online for other 'better' solutions. I found this example which uses PagedList.Mvc NuGet...
Here is my first attempt to solve Jumble puzzle: import argparse from itertools import permutations parser = argparse.ArgumentParser(description='Solver for Jumble') parser.add_argument('jumbledwords', nargs='+', help='One or more jumbled words') argv = parser.parse_args() # http://www-01.sil.org...
I am solving this question: It's not the rivers that you might be thinking about. The question revolves around the concept of digital rivers. A digital river is a sequence of numbers where the number following n is n plus the sum of its digits. FOR EXAMPLE 12345 is followed by 12360 since 1+2+3+4+5=15 and so 123...
The next version of rubberduck is going to include a pretty nifty "goto anything" / find symbol navigation tool that lets the user enter an identifier name in a combobox: UI To achieve the templated dropdown I had to introduce some WPF interop. Here's the markup: <UserControl.CommandBindings> <CommandBinding Com...
I have written a C program to generate a PPM (Portable Pixmap) image of the Mandelbrot set. The program implements many things in C I am fairly unfamiliar with (Structures, error handling, use of new libraries (complex.h), and files (I'm completely unfamiliar with image files)) and the purpose of writing this program i...
Today I tried solving this problem on SPOJ, in which you reverse the digits of two numbers, add them, and print the reversed digits of the sum. (When reversing, leading zeroes in the result should be dropped, and trailing zeroes in the result shouldn't happen.) I used C++ to write the code for this problem. My code go...
I am in the process of writing tests for my JS code with CasperJS and Mocha. I have a function that changes the DOM and gets run on page load (through jQuery's document.ready event). I'm wondering what the best practice is for testing this kind of code. For example, I have a function removeElements that gets run before...
I'm moving some octagons around and I found a serious bottleneck: @win.event def on_mouse_drag(x, y, dx, dy, buttons, modifiers): for o in octagons: o.vertices = tuple(chain.from_iterable( (o.vertices[i]+dx, o.vertices[i+1]+dy) for i in range(0, 18, 2))) The program starts lagging when about 1000 points (1...
I kinda got the idea after playing Adventure Capitalist, since that goes up to 10300. I found a website that explained how to go up to 10^3000, so I mainly did this as a challenge to see if I could do it. Also, I'm fairly new to writing the documentation bits, so feedback on what I did well/not so well would be appreci...
This code plays a note for a specific period of time using NAudio.dll 1.3.8. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NAudio.Midi; using System.Threading; namespace SoundVision { class Note { public Note(MidiOutWrapper mid...
This is the code I'm using to GET the definition of a word from Wordnik's REST API. I don't want to ignore any error but this is causing the code to be ridiculously long. I'm new to Swift so I'd appreciate it if someone could explain how best to trim it down. class func define(params: DefinitionParameters!, delegate: W...
I have a use case which says: Your REST service will consume a JSON object that contains a list of emails for subscribers at the start of the subscription period, and a list of subscribers at the end of the subscription period. Your service must return a list of subscribers who are new, subscribers who stayed,...
My job is to make a specified java objects from web page that contains following text: Companies: [{"companyName":"Tire Systems","companyID":1},{"companyName":"IT Enterprise","companyID":2},{"companyName":"Car Manufacture","companyID":3},{"companyName":"Electro Market","companyID":4}] Materials: [{"name":"Winter Tire"...
I've written a simple Diceware passphrase generator based on this Stack Overflow question and the top answer. Briefly, in the Diceware method, a die is rolled 5 times for each word in the passphrase and the results matched to the corresponding word in the word list which is of the form: 16226 cask 16231 casket 1623...
My project has three classes: Card, Deck, and BridgeConsole. The Card class has two fields: int rank and int suite. It has three methods: toString, getSuitAsString, and compareTo: public class Card implements Comparable<Object>{ int suit; // 0-Hearts, 1-Clubs, 2-Diamonds, 3-Spades int rank; // 2-10, 11-Jack, 12-Queen, ...
I am writing some code that will serve a website and I have some questions about my "architecture". Domain - I have a database and and at the lowest level I have the **Domain* *package that contains the classes that represent the tables of the database. I use Hibernate and lazy fetch for relationships. Access This pac...
I am trying to make a function for Select statements. It will give result based from the parameters passed. I tried using it and it gives the results I am expecting. I know that it is still unpolished but I would like to know what are the critical things in it that should be fixed or improved so that it would be ready ...
Can this code in any way be improved or optimized? I'd appreciate any clever tricks or Pythonic expressions that may remove some more brute force elements from my solution. Also, is there possibly a more intuitive way of approaching this problem that I couldn't see? Problem statement: Largest product in a grid In the...
I solved this challenge. It passes all the test cases, but I'm not very happy with my solution. I'm convinced this could be done much smoother (i.e less code) Swap operation: Given a tree and a integer, K, we have to swap the subtrees of all the nodes who are at depth h, where h ∈ [K, 2K, 3K,...]. You are given a ...
I have a positive integer n. I want to lazily loop over a range of integers less than n consisting of a) integers divisible by 3 (excluding zero) in reversed sorted order and b) zero and integers not divisible by 3 in any order. Is this a very stupid solution? I couldn't think of another way of doing it without having ...
I frequently get a situation in which I want a pretty binned column from a vector of values, so that I divide the vector in approximately even ranges and choose 'sensible' values so that it looks pretty when using the column in pivot tables or other reports. Sensible herein includes rounding values like 10123.1 to 1000...
I just started out a new job as a C# programmer on .NET 3.5. My manager gives me total independence on how I build my modules, which is generally a good thing, but there are minuses too. Having too much "freedom" tends to make me wander to places you wouldn't have if you had some strict guidance. My project involves ma...
I am brushing up on my Java skills by trying to solve the below assignment problem I found on the internet: Write a Java method that accepts two strings as parameters and returns a string that contains all unique two-character strings whose first character comes from the first string and second character comes from th...
I want to convert a one dimensional array to a two dimensional array with the following conditions and have followed the code from this question - https://stackoverflow.com/questions/1817631/iterating-one-dimension-array-as-two-dimension-array. The 2-dimensional array has to be copied from the one dimensional array and...
I hesitated quite a bit of time before posting this question since the code to review is more or less a monster (with regards to its size). It is a basic mathematical expressions evaluator, but with one interesting additional feature: you can register callbacks that can be used in the expression to evaluate. First of a...
This question goes hand in hand with another question about a mathematical expressions evaluator in C++. The other question is meant to be read first, this one is but a complement to expose the internals of the evaluator and the overall architecture to explain how the details work. The tokens mechanism A token is a han...
Cost of nodes are represented by a matrix (called world), heuristic cost estimate/g score/f score are all represented in matrices. The world and its size are stored in global dynamic variables. It looks like this: 1 1 1 1 1 1999 1999 1999 1999 1 1 1 1 1 1 1 1999 1999 1999 1999 1 1 1 ...
Currently I'm developing my business entities. I feel that the structure is a tad cumbersome. What I mean is that a store on a particular day can have different open and closing times. So it's not as simple as a store opens and closes at 09:00 and 17:00 respectively every day at the week. A store may open at 09:00 and...
For a given set of denominations, you are asked to find the minimum number of coins with which a given amount of money can be paid. Assume that you can use as many coins of a particular denomination as necessary. For example, given the denominations 1, 3, 4, and the target amount 6, the algorithm should find the optim...
I've made a simple caching function for my jQuery ajax calls. I know about the $.ajax() cache setting, but I don't use it for various reasons. One of the most important one is it being limited to GET (and perhaps HEAD?) requests. If a cached value is found, and is a reference type, I'm returning a deep copy rather than...
I'm new to Python, and pretty much programming/scripting. I'm just looking for someone to critique my methods and tell me if there are more efficient ways to do things. #!/usr/bin/env python3 # # # A quick script to create a civil war game ############################ # DECLARE GLOBAL VARIABLES # ####################...
A couple months back I made a go fish game in Go, just for the sake of that pun. It was pretty poorly done and made experienced Go-ers cry when they looked at it. I rewrote some of it to be more standard, but I'd still like critiques from the 95% of the world with more Go experience than me. For those unaware, Go Fish ...
I have the following code to find the longest list in a list of lists: max_len = max([len(path) for path in paths]) [path for path in paths if len(path) == max_len][0] Each path is a list of integers. paths doesn't have to be a list. So if I have, for example: path_a = [1, 2, 3] path_b = [1, 4] path_c = [3, 5, 6, 2,...
I wrote 2 versions of problem 22 on Project Euler: Using a text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. For example, when the...
I was inspired by Number Wizard game question and I decided to write my own version of the game. My goals were to follow the SOLID principles and make the logic UI independent. I'm a bit confused about the outcome, though. I think my solutions reads much easier than the version in original question, but on the other h...
I've written a simple script that takes a string filled with brackets and strings and builds them to a dictionary. Example Input: string_1 = '(()())' string_2 = '((a)(b))' string_3 = '(a(a)b(b)c)' string_4 = 'a(a(a)b(b)c)b' string_4 = 'a[a{a}b{b}c]b' string_5 = 'beginning(content[word]{another word})outside' Output fo...
This program asks a user to input any number equal to or between 1-12. It then converts the number to a message that will be printed (Copy the program to see it yourself). Is there a way to make the code shorter by still using the switch statement? This is homework, so using a switch is a requirement. import javax.sw...
Printing to stdout is thread-safe in many systems when using printf or std::cout, but not in all systems (Windows!). So I decided to make my own thread-safe and type-safe printing function with some help of C++11 variadic templates functions. #include <iostream> #include <iomanip> #include <mutex> class Mutex:private ...
On this site this site, I have some code which you can see below which figures out the offset for each post from the top of the document and assigns a colour from each post to the header when it scrolls into view. I am having to wait for the window load event until the code works which really is not very elegant. Can a...
Imagine a safe with a 4-digit code, and accepting a continuous stream of code entries, such that when the 4 digits are seen in the right sequence, the safe opens. Generate a short string that contains all possible code combinations, so that when you feed it to the safe, it will inevitably open. The string should be as...
I am curious if it would ever be in good practice to omit constructor definitions from a class. Here, the intention of the Temperature class is to simply convert between one temperature scale to another. Since there are three scale measurements, kelvin, Fahrenheit, and Celsius, I decided it was best to define specific ...
I am writing a Selenium framework that should be really easy for a tester with relatively little Java knowledge to use and write tests for. In order to keep the framework as user friendly as possible, I've noticed that I am writing a lot of statics so that the tester doesn't have to instantiate the page objects and met...
So this code is not yet completed. The end result has to calculate the average grade by each question. A=1 b=2 etc... and checks if the question is passed or not. this is what I got this far. #include <stdio.h> #define ROW 6 #define COLOMN 5 int input[ROW][COLOMN] , row, column; int main(void) { float passedte...
Just for learning and practicing I've created a completely recursive version of the merge sort algorithm. I've tested it a little bit and it seems working, but I'm quite sure that it can be largely improved. In particular, I'm hating the long if-else conditional inside the sort function. I think it's really bad written...
I am new to C# and develop a configurable PasswordService class. As the code works the next step is to improve the code. Right now there are the following options: Set alpha characters and the number of alpha characters that has to be in the password. Set numeric and the number of numeric characters that has to be in ...
In preparation for interviews, I have written a solution to this question: Given a sequence of numbers (34128) and an input map such as a dial pad on a phone (2->[a,b,c], 3->[d,e,f], 4->[g,h,i]) write an algorithm to return all possible words from the sequence. E.g. Input: 232 Output: [ada, adb, adc, aea, aeb,...
I wrote a program that reads a text file and then outputs the unique words, their frequency, and the line numbers that word appears on. It also counts the number of sentences in the text file. All of this information is then outputted to a text file. I currently have all of the code in one class object. What wou...
I am scraping a Wikipedia page, getting info from that page and instantiating a new object with the information collected: require_relative '../config/environment' def get_winner award = Nokogiri::HTML(open("http://en.wikipedia.org/wiki/Academy_Award_for_Best_Picture")) year = nil award.css('table.wikitabl...
My C++ was starting to get rusty and I never touched some of the newer features. Reason enough to try something simple and make it overly complicated: FizzBuzz with bonus features. For now we'll call it FizzBuzzWoofFooBar. The FizzBuzz idea is to check whether an integer is dividable by 3 and/or 5, the first two primes...
I am preparing to coding interview and I met this task today: You are given 30-bit unsigned integer N. A right cyclic shift of N by K bits is the result of performing a right cyclic shift of N by one bit K times. Leading zeros may appear. For example: the right cyclic shift of 9736 by one bit is 4868, the right cyclic...
I want to find the highest number in a time series, in the most efficient way. To avoid iterating through all the look back periods, I'm only iterating in case the current high number has just been discarded. I'm avoiding enqueue dequeue for the same performance reasons. What would be a faster algorithm? class Program ...
I have searched around but I was not able to find a complete implementation of the memoize pattern in a multithreaded context. It's the first time playing with thread synchronization. The code seems to works, but I am not able to test it extensively, in particular to find if there are race conditions. Do you think ther...
Swift's SequenceType is a useful means of generating a sequence of values, and it makes it particularly useful iterate over these values. I don't really have much experience with these SequenceType types, so I wanted to implement my own for some practice and learning. What better sequence to take a look at than a Fizz...
I'd be interested in hearing what folk think are the pros and cons of the following two ways of writing classes like the following Circle, Square and Rectangle classes in Swift. The first way has them extending a superclass (ShapeSC) with methods. The second has them implementing a protocol (ShapeP) with computed prope...
Let's say I am trying to build an opinion poll app, such that I can create a template of an opinion poll, give it multiple sections/questions, assign multiple people to different copies of a given question, create varying measures (happiness, successfulness, greenness) and assign different questions different weights t...
I've written a small program to detect the human language of a document or text fragment. I tried to stick to good design principles and I tried to make it pretty robust. I would be generously described as an intermediate programmer so I'm sure there are things that are bad-smellish that didn't even register with me. ...
I built this simple application to facilitate communication between two or more machines on a local area network. As each client starts up, it broadcasts and receives broadcast packets; allowing for the omission of inputting a peer's IP address. It then creates a new connection to each discovered peer (even to itself),...
I have a question about dependency injection and best practices when using simple classes which are meant to be created often, which have dependencies on external services. Here's a (vastly) simplified version of what I'm working on: app.js import {Factory} from './factory.js'; import {Convert} from './convert.js'; le...
I'm working on my library. It's just a boilerplate, wrapping some script code, with helper functions, some plugin implementation, required meta tags etc. How can I develop this better? // Namespace var KY = { init: function () { this.general.init(); this.ajax.init(); this.loadMore.init(); ...
I'm looking for a very simple (at first sight) CommandBus, which will handle some ICommand publication. The CommandBus implementation will find the appropriate IHandler to Execute the Command and then Notify some possible IObservers. My first step is to make it work, I've chosen to use a synchronous dependency injectio...
I want to read a file containing comma-separated values, so have written a finite state machine: private IList<string> Split(string line) { List<string> values = new List<string>(); string value = string.Empty; ParseState state = ParseState.Initial; foreach (char c in line) { switch (state) ...
As part of the distinction requirement, I am required to ask for testing/review of my code. There was no time allotted for this in class, and as such I am turning to the folks of StackExchange for help! This is a great way of doing it for me, as I can directly reference it in my bibliography, and easily format the crit...
I am seeing that this is actually not in accord with the difficulty level said there. Firstly I cannot list all possible improvements it could have. /* * A palindromic number reads the same both ways. The largest palindrome * made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the * largest palindro...
I have a script which is having too many modules. The script is working perfectly, but the only issue is it is taking too much time and I need to reduce the complexity of the script. I have a source file (it can have multiple rows of data, each column separated by a '|'). The script should check all the rows for all t...
Over the years I’ve seen many C# sieves and despite their varying internals all that I have seen invariably are a static method that returns a List<int>, perhaps with the occasional rare exception of an Enumerable<int>. This is fine for small collections. Granted relatively speaking for some people a 1 million item l...
I wrote a set of python classes for solving the change making problem, in various forms. Given the coin denominations and values: Find all possible ways of making change. Find a best way of making change (minimize number of coins). Determine whether it is possible to make change. This version of the project on gith...
I recently wrote a name generator that uses a DTMC underneath (I asked about it here) and, since I'm not entirely confident I did it right, I wrote a script to check my code, or at least its output. It works pretty well, but, being new to the language, I want to know how to make it more idiomatic. Performance boosts (i...
I'm learing Python by writing a program to solve some housekeeping I do weekly, namely renaming PDF files according to rules given in a text file. My end goal is to have idiomatic Python, with full test coverage. I have done some refactoring, and written a couple of tests. Ideally I would have done TDD from the beginni...
Here I have a method for reading the contents of a file into a buffer and returning whether or not it is successful. Here is what I would like reviewed: Speed: Am I reading in the file as fast as possible? Bugs: Are there cases where my code could fail or give unexpected behavior? Syntax/Styling: How does my code lo...
Is there any way I could improve this script, such as by writing it in fewer lines (more efficient)? I'm very interested in keeping my code dry and fast! Also, if there is a way to make it more dynamic don't hesitate to tell me! <?php /* Connect to an MYSQL database Using credentials and PDO(PHP DATA OBJECT) */ ...
About to get back into coding, so I implemented linear probing in Python. How did I do? Anything unnecessary? Am I using "global" right? I originally wanted to use an array with a fixed length, but couldn't get it to work. list = ["x", "x", "x", "x", "x", "x", "x"] state = 0 def main(): #tests linearProbing(1) ...
This is my first attempt at a program (outside of school) and I was trying to implement and learn polymorphism on a conversion calculator for volumes and weights. I found myself using long switch statements in the GUI to test user inputs against the units in order to make the calculations. Is there a better alternativ...
I made a very simple calculator in C that allows the user to perform calculations like addition, subtraction, multiplication and division. This is my first C program that I've made outside of my University course. It would be great to get some feedback on this program so that I can avoid bad practices early on in my co...
I want to thank you guys firstly for your previous comments and feedback. Really appreciate it. I am learning C with school at the moment, but I plan to be "fluent" in C at the end of august of this year. For school I have to write the following program: Open up a file. The file is a *.txt one. It consists of 32 num...
I wrote this little piece of script for my workplace (insurance, etc.) to help our admins, as a light and simple file I can just email to my colleagues. The purpose of it is to calculate a prorated refund in case of a policy holder cancelling it. Basically a policy's purchase value "ticks down" gradually after a certai...
It looks like this is a really classical question, but I'd like to ask it one more time as all those solutions look quite long and complicated for me (maybe because I am dumb :) ) So this is a Graham convex hull algorithm from the very beginning of the "Real World Haskell" book. And a perimeter function just for the s...
I decided to write a very simple web-game: function write_at(x, y, text, color, font) { ctx.fillStyle = color || "black"; ctx.font = font || "50px Arial"; ctx.fillText(text, x + 50, y + 50); } function write_at_random(text, color, font) { write_at(random_choice(range(0, canvas.width - 250)), random_choic...
I have these two methods: private static OpeningDay GetUsallyOpeningHour(List<OpeningDay> openingHoursDaily, DayOfWeek dayOfWeek) { var listOfSpecificDayOfWeek = openingHoursDaily.Where(x => x.DateTime.DayOfWeek == dayOfWeek); if(listOfSpecificDayOfWeek.Any()) return listOfSpecificDayOfWeek.GroupBy(x ...
I have this bit of code that needs refactoring/simplification. The below grabs the planning data for view A and B. Then it joins the planning and matching image for view details. So then it determines if it should set the buttons to be disabled or not based on whether or not, if the data is empty/null or not. I think ...
This is my first time using pytest. All feedback for this test case is much appreciated. import pytest from mock import mock_open, patch def get_file_contents(file_data): with patch.object('builtins.open', mock_open(read_data=file_data)) as mock: with open('mocked_file') as f: return (line for line in f....
Find the kth largest element in an array of integers. You may assume that: 1 <= k <=size(array). Any comments? Is there a more efficient solution? public int findKthLargest(int[] nums, int k) { int p = 0; int numElements = nums.length; // create priority queue where all the elements of nums will be sto...
Below is my working code written as an exercise in wildcards in generics and Java 8 type inference. My question will be about the commented line in union() method. I needed to create an instance of the interface type that does not include a static factory, so I was left with (seemingly) two choices: Use concrete im...
I have 5 nested for loops below, to add rows of data from multiple files to one of two lists. Is there a more pythonic way of doing this? I've come across an iterator-generator method named iteritems() -- could this be used to make this code more pythonic? # 5 nested loops for root,dirs,files in os.walk(src): fi...