Irk a Politician This Holiday Season by Giving to These Progressive Causes

Republican leaders won’t thank you, but others in need will.

For some progressives looking for holiday gifts, there are guides to ethical and feminist products. Others prefer to donate to an organization or cause. This holiday season, let your gift-giving be inspired by celebrities and their charitable donations. Celebrities like Mila Kunis have been donating to Planned Parenthood in Vice President Mike Pence’s name—and others have followed suit.

Instead of donating to a charitable organization in the name of a loved one or friend, try gifting in the name of a politician who stoked the dumpster-fire of 2017 politics. Support the work of these important organizations and give a reminder that the resistance is stronger than ever.

1. If the Alabama special election had you on the edge of your seat and the thought of child-molester Roy Moore (who has still not accepted the election results) makes you want to punch a wall while throwing up…

Photo Credit: Emily C. Bell / YouTube

…then donate to organizations and campaigns working to support voting rights and black candidates. When pollsters examined the special election voter demographics, Doug Jones was victorious because of black voters, specifically black women (96 and 98 percent voted for Jones, respectively). In response, The Cut released a list of organizations and campaigns working toward voting access and political empowerment of black women. Check out Woke Vote and Higher Heights, and give Roy Moore a reminder of the power of local organizing.

2. If you despite head of the EPA Scott Pruitt for refusing to recognize human contributions to climate change and for subsequently leading the government in throwing the planet under the bus in 2017, and you’re appalled by the plethora of climate change deniers, not just in the White House but also in Congress…

Photo Credit: Gage Skidmore/WikiCommons

…then support those who are standing up to them, like the youth activists who protested at the UN climate summit. You can also donate to organizations educating and raising awareness about climate change, including Earthjustice and 350.org.

3. If you oppose politicians like Representative Steve King for his support of the DACA repeal and for saying Dreamers can “live in the shadows”… 

Photo Credit: WikiCommons

…donate to organizations like United We Dream, which is calling for a clean #DreamActNow and organized a national call day on Thursday.

You can also support organizations like Movimiento Cosecha and the Immigrant Defense Project that are fighting back on Trump-administration policies, protesting the actions of ICE and advocating for the rights of immigrants.

4. If you’re outraged over Donald Trump ignoring the crisis in Puerto Rico…

Photo Credit: Shealah Craighead/ WikiCommons

…and his childish behavior when he visited:

…donate to organizations that are providing services on the ground in Puerto Rico and working on rebuilding efforts due to the destruction of Hurricane Maria. A list of reputable organizations includes Friends of Puerto Rico and Light and Hope for Puerto Rico: A Citizen Campaign, which is raising money to purchase and deliver specific supplies: solar lights, phone chargers and washing machines that don’t require electricity.

5. If you hate that Health and Human Services Secretary Tom Price and GOP lawmakers are reducing access to birth control, something Price clearly has no knowledge of…

…and the GOP tax bill, which is an overall travesty for poor people, because of health care provisions that will remove the individual mandate and hurt access to birth control…

Donate to organizations concerned with access to birth control and reproductive healthcare, like the Center for Reproductive Rights and Planned Parenthood, and feel inspired by their recent activism to stand up to the Trump administration for the birth control rollback:

 

 

 

 

Related Stories

  • In Alabama, Black Women Saved America From Itself—as They’ve Always Tried to Do
  • The Alt-Right Is Melting Down in the Wake of Roy Moore’s Stunning Defeat
  • Whitefish Energy Fleeced Puerto Rico During Recovery Efforts: Report

Creating our own factory method in Java

Creating our own factory method in Java

Any factory method is created as a method belonging to an interface or abstract class. Hence that method is implemented, in the implementation classes or sub classes as case may be.

What are factory methods ?

A factory method is a method that creates and returns an object to the class to which it belongs. A single factory  method replaces several constructors in the class by accepting different options from the user , while creating the object.

For example, to create a factory method getFees() that will give the fees details for a course in an engineering college, we need to perform the following steps :

1> create an interface or abstract class
interface Fees {
   double showFees();
}

2>  Implement the abstract , public methods of the above interface.
class CSE implements Fees {
public double showFees(){
return 120000; // assumed some constant figure
}
}
// their can be more implementation classes also.

3> Create a factory class that contains factory method by the name getFees(). Mostly factory methods are written as static methods.
class CourseFees{
public static Fees getFees(String course){
if(course.equalsIgnoreCase(“CSE”))
return new CSE();
else if(course.equalsIgnoreCase(“ECE”))
return new ECE();
else return null;
}
}

// getFees() method takes the coursename from the user and creates an object either to CSE class or ECE class depending on the user option.

4> Call the factory method like this :
Fees f = CourseFees.getFees(name);

// In the preceding code, an object of CSE class or ECE class is returned by getFees() method. Since CSE and ECE are the implementation classes of Fees interface, we can use Fees interface reference ‘f’  to refer to the objects of these classes. Hence, if we call f.showFees(), then the showFees() of that particular class either CSE or ECE will be executed and corresponding fees will be displayed.

// complete program : combining all 4 steps as above
import java.io.*;

interface Fees {
   double showFees();
}

class CSE implements Fees {
public double showFees(){
return 120000; // assumed some constant figure
}
}

class ECE implements Fees {
public double showFees(){
return 110000; // assumed some constant figure
}
}

class CourseFees{
public static Fees getFees(String course){
if(course.equalsIgnoreCase(“CSE”))
return new CSE();
else if(course.equalsIgnoreCase(“ECE”))
return new ECE();
else return null;
}
}

// using factory method
class Sctpl {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter course name”);
String name = br.readLine();
Fees f = CourseFees.getFees(name);
System.out.println(“The fees is Rs “+ f.showFees());
}
}

Civilization VI

I haven’t played Civilization VI yet. I am a fan of the series. But I have too many games and too little time, and I didn’t want to pay full price for yet another iteration of the same game. I was still waiting for the price to come down below $30 when I got the news that the full Civ 6 game has been ported to iOS. Yes, you need a newer iPad to play and it is battery-hungry, but it is the *full* Civ 6, not a toned down mobile version. That is pretty remarkable. So I downloaded the game for free, which lets you play 60 turns with the Chinese empire to see how it works. And then I balked at buying the full version for $60. I didn’t even want to pay that for the PC version, and for an iOS game that is very expensive.

So while I was still pondering what to do, I got another piece of news: You can this month get Civilization VI (PC version) plus 2 expansions plus a collection of other games in the Humble Bundle Monthly for $12. That is basically a subscription service where you pay $12 per month to get a bundle of games every month. But if you only want Civ 6 you can of course unsubscribe after 1 month. As this is the lowest I have ever seen Civ 6 go for, I ended up buying the game that way.

Not sure when I will get around to actually play it, I am still very busy with Zelda – Breath of the Wild. But as an opportunity to get Civ 6 cheap this is certainly worth mentioning. The offer is available until the end of the month.

Robert Mueller Has the Trump Team Panicked, No Matter What the President Says

The special prosecutor has reportedly obtained thousands of campaign emails.

Donald Trump responded to questions on Sunday saying he had no intention to fire Special Counsel Robert Mueller. But while Trump was making this statement, both his team inside and outside the White House and Republicans in Congress continued to beat the drums for Mueller’s dismissal.

The president’s comments came a day after a lawyer representing Trump’s transition team accused Mueller of wrongfully obtaining thousands of emails sent and received by Trump officials before the start of his administration — a legal and public relations maneuver seen as possibly laying the groundwork to oust the special counsel.

The revelation that Mueller has obtained a large number of emails issued during the transition period had clearly sent Trump’s team scrambling. It’s not just that Mueller had this material now, but that he seems to have obtained it weeks ago, meaning that recent questioning of everyone from Jared Kushner to Hope Hicks may have been responding to questions for which Mueller already had the answers in hand. Considering that half the people Mueller has already indicted were convicted for lying, that has to have everyone in the White House carefully reviewing their time with the special counsel.

The Republican play on Mueller’s acquisition of the emails is that it is “illegal”—a charge made without bothering to state just what law might have been broken. On Sunday, Trump joined in the vague grumbling.

Trump criticized Mueller for gaining access to those emails, telling reporters the situation was “not looking good.”

But the letter from Trump’s lawyer and additional charges of partisanship by Mueller’s team, was enough to generate a rare statement from Mueller’s spokesman, Peter Carr.

“When we have obtained emails in the course of our ongoing criminal investigation, we have secured either the account owner’s consent or appropriate criminal process.”

Mueller’s gathering up the transition emails is giving Donald Trump a sad.

“It’s quite sad to see that,” Trump said. “My people were very upset about it.”

The potential for additional indictments over lying under oath gives Mueller even more leverage in his efforts to collect testimony directly concerning Trump … but Trump is maintaining an attitude of reduced concern.

Trump has spent much of his first year in office so enraged by the federal investigation into Russian meddling in last year’s election that lawmakers who work with him tried to avoid the issue entirely and his friends worried that Trump might rashly fire the special counsel. But in recent weeks, Trump has privately seemed less frustrated about the investigation, according to multiple sources who have spoken with the President.

Trump has been telling people that he expects to soon be cleared “in writing,” and keeps insisting that Mueller’s investigation will soon be over.

“The President’s mantra is ‘All this Russia stuff, it’s all going to wrap up soon.’ He repeats it as fact,” said one source who speaks to Trump. “Part of me is like — ‘Are you serious? You believe this?'”

But there’s no indication that the special counsel is running out of either witnesses or information. Just eight months in, Mueller’s investigation is a less than a quarter of the length of the average special counsel or special prosecutor investigation, and less than a tenth of investigations like Iran/Contra or Whitewater. It could easily proceed through the length of Trump’s time in office—whether or not that time is shortened.

For the investigation to end anytime soon, as Trump indicates, it will likely be because Trump and the Republicans step in to halt the process before it can complete. But while others are working to tear down Mueller’s reputation and attack the integrity of the investigation, Trump himself seems to be spending time in fantasyland.

Three sources familiar with the President’s recent conversations about the investigation said Trump has become convinced that he will receive a letter of exoneration, which would be unusual. One source worried Trump would have a “meltdown” if that doesn’t happen.

Maybe he expects that letter to come with the signature of Jefferson Sessions. Or new special counsel Sean Hannity. And maybe they’ll also give him a gold star.

 

 

 

Related Stories

  • The One Scenario in Which Trump Would Risk Impeachment and Fire Robert Mueller
  • Donald Trump Jr. and Ted Cruz Mock Barack Obama with Bizarre Cookie
  • Fox News’ Jeanine Pirro Delivers Her Most Disturbing Monologue of Trump’s Presidency

The One Scenario in Which Trump Would Risk Impeachment and Fire Robert Mueller

The president reportedly expects to be exonerated soon.

President Donald Trump believes that special counsel Robert Mueller will soon send him a letter that completely exonerates him of any wrongdoing — but the president’s allies fear that such a letter will never come.

CNN reports that Trump has recently been boasting to allies that the Russia probe will be over very shortly, and that Mueller will personally exonerate him. The president believes this, CNN’s sources say, because his attorneys have tried to manage him by telling him that he faces no real danger from the probe.

However, some of the president’s allies believe this is delusional, wishful thinking — and they fear what Trump will do if that exoneration letter never comes.

One Trump ally tells CNN that the president will likely have a “meltdown” after months go by without an exoneration letter, after which “he’ll try and fire Mueller and then be impeached.”

Another Trump ally similarly warns that Trump’s lawyers are playing a dangerous game by buttering him up with happy talk about the Mueller probe ending shortly.

“I’ve known him long enough to know that disappointing him is a problem and they’ve built up a level of expectations for him that are unrealistic,” the source said. “[They’ve] lulled him into a false sense of security.”

 

 

Related Stories

  • MSNBC Shows Frightening Clip of Trump and Putin Using Exact Same Talking Points
  • MSNBC Shows Scary Clip of Trump and Putin Using Exact Same Talking Points
  • Fox News’ Jeanine Pirro Delivers Her Most Disturbing Monologue of Trump’s Presidency

Doublethink

And if all others accepted the lie which the Party imposed – if all records told the same tale – then the lie passed into history and became truth. “Who controls the past,” ran the Party slogan, “controls the future: who controls the present controls the past.” And yet the past, though of its nature alterable, never had been altered. Whatever was true now was true from everlasting to everlasting. It was quite simple. All that was needed was an unending series of victories over your own memory. “Reality control,” they called it: in Newspeak, “doublethink.”

I have a memory problem. My memory is too good. When a few years ago I became interested in the history of the American Civil War and read a lot of books, saw a lot of documentary films and the like, the culture wars hadn’t reached that area of history yet. And so my memory tells me that in those unpolitical history books Robert E. Lee was depicted as a decent person. Yeah, sure, he was fighting for the losing side, and the losing side was obviously pro-slavery and thus on the wrong side of history. But history, before it got redacted by “the Party”, said that Lee wasn’t a political firebrand. He only entered the war reluctantly, out of a sense of duty to his state. He was a slaveholder in a state where everybody who had any social status was a slaveholder. At the time history still judged him on his actions as a general in the war. And on that count he wasn’t doing all that badly, being both competent and humane. If you took history documents from a decade ago and judged by them who the more decent human being was, Robert E. Lee would probably win over William T. Sherman, who was fighting on the winning side, but with far more brutal methods.

Of course that was a decade ago, and I really need to reformat my memory. Today the party line is that the statue of William T. Sherman in New York Central Park is honoring a hero, while the statues of Robert E. Lee are being torn down everywhere for being too offensive. An Asian American ESPN sports commentator, who unfortunately has the name Robert Lee, was pulled from a game because his name was considered too toxic to be on TV.

Now statues of the losers being torn down is quite a usual occurrence after a war, don’t we all remember the pictures of people tearing down statues of Saddam Hussein? What is somewhat weird is doing it 150 years after the war ended. Hey guys, we just discovered that Robert E. Lee was fighting for the slave-holding South, so we need to remove his statues now! Sorry we didn’t notice that earlier! What on earth has Robert E. Lee done in the past years to deserve such a fate now that he didn’t deserve a decade ago?

Although blaming “both sides” apparently isn’t politically correct any more either (or maybe it is if the other side is the “right” one?), I would say that the extreme right rallying around confederate symbols is of course a major trigger to those symbols suddenly becoming politically incorrect. That makes Robert E. Lee a victim, being caught in the middle of a culture war. It might have some rather hilarious results if the extreme right would chose symbols that more difficult to tear down, like the American flag. To some extent the Constitution of the United States of America is already a symbol of the extreme right, if you find somebody with a copy of it in his pocket he probably is a Trump voter. Or an immigrant in the process of learning it by heart as part of the naturalization process. Or a supreme court judge. So fortunately we don’t have to burn it yet in order to be politically correct.

Nevertheless, as a student of history I find the efforts to change or re-interpret history 150 years later somewhat worrying. Imagine we would tear down the Arc de Triomphe in Paris, because Napoleon lost his wars 200 years ago, and for some reason we now find his symbols offensive. When the Taliban destroyed the Buddhas of Bamiyan, we lamented the loss of history. Isn’t the preservation of history a bigger value for humanity than the need to remove anything that could be deemed offensive? If the culture wars rage back and forth, with both sides being in power at some point, aren’t we in danger of losing all our history, because it doesn’t fit with some party line? If history is offensive, which it certainly sometimes is, aren’t we still losing more by erasing it than by preserving it as a reminder to do better next time around?

Jared Kushner and Ivanka Trump Reportedly Face New Financial Disclosures Lawsuit

The couple allegedly made significant omissions on their disclosure forms.

President Donald Trump’s daughter Ivanka and his son-in-law Jared Kushner were hit with a new lawsuit on Sunday alleging they made significant omissions on their federal financial disclosure forms.

Politico reported Sunday night that Washington lawyer Jeffrey Lovitky filed a complaint in U.S. District Court in Washington alleging that the two White House aides neglected to share information about some 30 investment funds in which they are invested. They also are accused of hiding the value of two investment vehicles in which they’re involved as well as income derived from them.

A large number of the holdings Kushner did report, the complaint states, are not listed in full detail due to “prior confidentiality agreements.”

However, Lovitky’s complaint said these agreements do not apply under the Ethics in Government Act (EIGA).

“The [Ethics in Government Act] does not allow a reporting individual to refuse to disclose the underlying assets of an investment vehicle, on the basis that such disclosure would violate a pre-existing confidentiality agreement. Nor does the EIGA allow a reporting individual to refuse to disclose the amount of income derived from any underlying asset of an investment vehicle, on the basis that such disclosure would violate a pre-existing confidentiality agreement,” said the suit.

Politico’s Josh Gerstein described Lovitky as “a health care finance lawyer who sometimes files civil rights cases.” He filed a similar suit against Pres. Trump himself earlier this year.

Kushner and Ms. Trump have been hit with repeated accusations of hiding information from federal regulators including charges that they failed to disclose millions of dollars of art in their possession. Kushner has had to revise his reports of meetings with foreign operatives and Russian banking officials multiple times, adding “more than 100 names” to the list last July.

Read the full report here.

 

Related Stories

  • Trump Didn’t Invite a Single Jewish Democratic Congressperson to the White House Hanukkah Party
  • Ivanka Trump and Jared Kushner Engaged in ‘Unethical’ Helicopter Use: Report
  • Treasury Secretary Steve Mnuchin Seriously Claims Ignorance of CDC Banned Words Report

“Hey Google” command for Assistant on Home now rolling out to phones too

There’s an advert currently doing the rounds for Google Home devices that plays up the smart speaker’s ability to recognize more natural sentences rather than rigid command lines. It’s not hard to see the advert as a thinly veiled shot at Amazon’s Echo smart speakers and Alexa’s stricter dialogue patterns.

To some extent this is true, as Google Assistant has been positioned as a friendly, more conversational digital butler ever since it first arrived on the first-generation Pixel phones last year. Yet unfortunately, actually kicking off the chat has always been a little clumsy due to the Assistant’s awkward ‘hotword’: “OK Google”.

Home users thankfully have a little more choice and can say “Hey Google” instead, but on smartphones it’s been “OK Google” ever since the dark days of Google Now. As of today, though, it seems that Google is rolling out the “Hey Google” command for Assistant on phones too.

More: What is Google Assistant? How can you use it?

Android Police reports that some users have begun receiving a notification prompting them to retrain their voice model settings to account for the new hotword. The feature began rolling out for some users back in October, but it appears this is happening on a universal scale.

I didn’t receive the notification personally, but after updating the Voice settings manually on my Pixel 2 XL I found that both “OK Google” and “Hey Google” are now both recognized by Assistant. You can do this yourself by heading to your Settings menu and then tapping Google > Search > Voice > Voice Match > Retain voice model.

Having two phrases instead of one on multiple devices is a step in the right direction for Assistant, but I still can’t shake the feeling that the insistence on using two specific, arbitrary phrases undermines Google’s claim that Assistant offers a more natural experience than its rivals – especially when you can wake Alexa with a single word or rename it entirely.

Which hotword will you be using, “OK Google” or “Hey Google”? Let us know in the comments.

Understanding Synchronous and Asynchronous JavaScript – paRt_1 : JavaScript – its DiFFereNt

Javascript logo
In JavaScript Synchronous and Asynchronous are very important concepts. Beginners might find them difficult to learn.
When two or more things happen at same time then it is Synchronous and when they don’t that’s Asynchronous. These definitions are easy to understand but it’s complicated than it looks from here. So let’s dig a little deeper. 
You’d probably call a normal function in JavaScript synchronous, right? And if it’s something like setTimeout() or AJAX that you’re working with, you will refer to it as being asynchronous, yes? What if I tell you that both are asynchronous in a way?
Let’s understand with an example. We’ll get help from Mr. K,

Scenario 1:-> Mr. K is trying Synchronicity 

Here’s the setup:
  1. Mr K is someone who can answer tough questions, and carry out any requested task.
  2. The only way to contact him is through a phone call.
  3. Whatever question or task you got, in order to ask Mr K’s help to carry it out; you call him.
  4. Mr K gives you the answer or completes the task right away, and lets you know it’s done.
  5. You put down the receiver feeling content and go out on a date.
What you’ve just carried out was a synchronous (back and forth) communication with Mr K. He listened as you were asking him your question, and you listened when he was answering it.

client calling server

Scenario 2:-> Mr. K isn’t happy with Synchronicity 

Since Mr K is so efficient, he starts receiving many more calls. So what happens when you call him but he’s already busy talking to someone else? You won’t be able to ask him your question – not till he is free to receive your call. All you will hear is a busy tone.

So what can Mr K do to combat this?
Instead of taking calls directly:
  1. Mr K hires a new guy, Mr J and gives him an answering machine for the callers to leave messages.
  2. Mr J’s job is to pass on a message from the answering machine to Mr K once he knows Mr K has completely finished processing all previous messages and is already free to take a new one.
  3. So now when you call him, instead of getting a busy tone, you get to leave a message for Mr K, then wait for him to call you back (no date time yet).
  4. Once Mr K is done with all the queued up messages he received before yours, he will look into your issue, and call you back to give you an answer.
Now here lies the question: were the actions so far synchronous or asynchronous?
It’s mixed. When you left your message, Mr K wasn’t listening in to it, so the forth communication was asynchronous.
But, when he replied, you were there listening, which makes the return communication synchronous.
Until now you must have understand synchronicity in communication. It’s time to bring in JavaScript in the picture.

JavaScript An Asynchronous Language

When someone labels JavaScript asynchronous, what they are referring to in general is how you can leave a message for it, and not have your call blocked with a busy tone.
The function calls are never direct in JavaScript, they’re usually done via messages
JavaScript uses a message queue where incoming messages (or events) are held. An event-loop (a message dispatcher) sequentially dispatches those messages to a call stack where the corresponding functions of the messages are stacked as frames (function arguments & variables) for execution.
The call stack holds the frame of the initial function being called, and any other frames for functions called via nested calls on top of it .

JavaScript Call Stack
JavaScript Call Stack

When a message joins the queue, it waits until the call stack is empty of all frames from the previous message, and when it is, the event-loop de-queues the previous message, and adds the corresponding frames of the current message to the call stack.
The message waits again until the call stack becomes empty of its own corresponding frames (i.e. the executions of all the stacked functions are over), then is de-queued.
Consider the following code:

function foo(){}
function
bar(){
foo();
}
function
baz(){
bar();
}
baz();

The function being run is baz() (at the last row of the code snippet), for which a message is added to the queue, and when the event-loop picks it up, the call stack starts stacking frames for baz(), bar(), and foo() at the relevant points of execution.

Push action in Call Stack

Once the execution of the functions is complete one by one, their frames are removed from the call stack, while the message is still waiting in the queue, until baz() is popped from the stack.

Pop Action in Call Stack


Remember, the function calls are never direct in JavaScript, they’re done via messages. So whenever you hear someone say that JavaScript itself is an asynchronous programming language, assume that they are talking about its built-in “answering machine”, and how you’re free to leave messages.

But what about the specific asynchronous methods?

So far I’ve not touched on APIs such as setTimeout() and AJAX, those are the ones that are specifically referred to as asynchronous. Why is that?
It’s important to understand what exactly is being synchronous or asynchronous. JavaScript, with the help of events and the event-loop, may practice asynchronous processing of messages, but that doesn’t mean everything in JavaScript is asynchronous.
Remember, I told you the message didn’t leave until the call stack was empty of its corresponding frames, just like you didn’t leave on a date until you got your answer — that’s being synchronous, you are there waiting until the task is complete, and you get the answer.
Waiting isn’t ideal in all scenarios. What if after leaving a message, instead of waiting, you can leave on the date? What if a function can retire (emptying the call stack), and its message can be de-queued even before the task of the function is complete? What if you can have code executed asynchronously?
This is where APIs such as setTimeout() and AJAX come into the picture, and what they do is… hold on, I can’t explain this without going back to Mr K, which we’ll see in the second part of this article. Stay tuned…

JavaScript Interview Questions for Freshers


What is JavaScript, really ?

JavaScript (“JS” for short) is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites. It was invented by Brendan Eich, co-founder of the Mozilla project, the Mozilla Foundation, and the Mozilla Corporation.

JavaScript is incredibly versatile. You can start small, with carousels, image galleries, fluctuating layouts, and responses to button clicks. With more experience, you’ll be able to create games, animated 2D and 3D graphics, comprehensive database-driven apps, and much more!

*For online documentation on JavaScript , refer the doc of creators – mdn

**For the best class-room training on JavaScript at Mumbai connect with Rocky Sir

Leaving out the very simple and basic Interview Questions, at what questions do the fresh web developers get stuck ?  Here is a list :

1. Before-the-first-Round-of-JavaScript-Interview-Questions

      download a short and sweet PDF


2. 10-common-JavaScript-interview-questions (Click on the Question for viewing the answer)


3. Step-by-step solution for step counting using recursion

step counting _sctpl

For example, if you wanted to climb 4 steps, you can take the following distinct number of steps:

1) 1, 1, 1, 1
2) 1, 1, 2
3) 1, 2, 1
4) 2, 1, 1
5) 2, 2
So there are 5 distinct ways to climb 4 steps. We want to write a function, using recursion, that will produce the answer for any number of steps
answer-to-step-counting-using-recursion

4. Determine overlapping numbers in ranges

You will be given an array with 5 numbers. The first 2 numbers represent a range, and the next two numbers represent another range. The final number in the array is X. The goal of your program is to determine if both ranges overlap by at least X numbers. For example, in the array [4, 10, 2, 6, 3] the ranges 4 to 10 and 2 to 6 overlap by at least 3 numbers (4, 5, 6), so your program should return true.
answer-to-determine-overlapping-numbers-in-ranges 



5. Find all duplicates in an array



This is a common interview question where you need to write a program to find all duplicates in an array. The elements in the array have no restrictions, but in this algorithm we’ll work specifically with integers. Finding duplicates in an array can be solved in linear time by using a hash table to store each element as we pass through the array. The general algorithm is: 


(1) Loop through the array
(2) At each element check if it exists in the hash table, which has a lookup of O(1) time
(3) If the element exists in the hash table then it is a duplicate, if it doesn’t exist, insert it into the hash table, also O(1)

for-complete-solution-to-finding-all-duplicates-in-an-array


6Two sum problem


The two sum problem is a common interview question, and it is a variation of the subset sum problem. There is a popular dynamic programming solution for the subset sum problem, but for the two sum problem we can actually write an algorithm that runs in O(n) time.

The challenge is to find all the pairs of two integers in an unsorted array that sum up to a given S. For example, if the array is [3, 5, 2, -4, 8, 11] and the sum is 7, your program should return [[11, -4], [2, 5]] because 11 + -4 = 7 and 2 + 5 = 7.

for-complete-solution-to-Two-sum-problem

7. Stock maximum profit

You will be given a list of stock prices for a given day and your goal is to return the maximum profit that could have been made by buying a stock at the given price and then selling the stock later on. For example if the input is: [45, 24, 35, 31, 40, 38, 11] then your program should return 16 because if you bought the stock at $24 and sold it at $40, a profit of $16 was made and this is the largest profit that could be made. If no profit could have been made, return -1.


for-complete-solution-to-Stock-maximum-profit