Given an array of integers, find 3 integers that sum to zero

Given an array of integers, find 3 integers that sum to zero

Output of algo:

Sum of 3 , -10 , 7 = 0
Sum of -15 , 8 , 7 = 0

Input for above output was:

int[] numbers2 = new int[7];
numbers2[0] = -15;
numbers2 [1] = 8;
numbers2 [2] = 3;
numbers2 [3] = -10;
numbers2 [4] = 7;
numbers2 [5] = -6;
numbers  [6] = 3;
get3IntegersSumming0(numbers2, 0);

private static void get3IntegersSumming0(int[] integers, int startingIndex ) {
  if(integers == null || startingIndex >= integers.length - 2  ) {
    return ;
  }
  get3IntegersSumming0(integers, startingIndex + 1);
  for (int i = startingIndex; i < integers.length ; i++) {
     int a = integers[startingIndex];
     int b = integers[startingIndex +1];
     int c = integers [i];
     if(sum(a,b,c) == 0) {
       System.out.println("Sum of "+a+" , "+ b + " , " + c +" = 0" );
     }
  }
}

Find Valid Words in a given String

Find Valid Words in a given String, in such a way that when they are combined produce the input string

public static void findWordsFromString(String str,int index, Set<String> words) {
  if(index > str.length()) {
    return;
  }
  findWordsFromString(str,index+1, words);
  for(int i = 0 ; i < index; i++) {
    String sub = str.substring(i, index);
    if(isValidWord(sub)) {
      words.add(sub);
    }
  }
}

Find All Permutations of a string.

Non Recursive Solution

public static Set permutationNonRecursive(String str) {
System.out.print(str);
char[] chars = str.toCharArray();
Set permutations = new HashSet<>();
for(int i=0; i < str.length() ; i++) {
for(int j = 0; j < str.length() ; j++) {
if(i != j) {
swapChar(chars, i, j);
permutations.add(new String(chars));
}
}
}
return permutations;
}

Recursive Solution

public static void permutationRecursive(char[] chars, int j, Set permutations) {
if(j >= chars.length) {
return;
} else {
permutationRecursive(chars, j +1,permutations);
for (int i = 0 ; i < chars.length; i++) {
if(i != j ) {
swapChar(chars, i, j);
permutations.add(new String(chars));
}
}
}
return;
}

public static char[] swapChar(char[] c, int i , int j ) {
char temp = c[i];
c[i] = c[j];
c[j] = temp;
return c;
}

Human Being – The most complex system in this world

Human being is the most complex system in this world.

It has many interfaces to interact with. It can be different for diverse people, which causes different definitions of itself in the dictionaries of others.

Sometimes it gets into unrecognizable states, and thus gets un-interpretable status which might be difficult to deal with or causes wrong results computed by others.

Sometimes it interprets the information with respect to its own thoughts, feelings and happenings in its life which might cause invalid arguments, bad interpretations, and red alerts which sometimes make relationships exit abruptly.

Sometimes it understands correctly what was not said but meant, and sometimes it doesn’t understand what was said correctly and clearly.

Sometimes it sees which is not visible, and sometimes it sees which never happened.

Having expectations is another complex phenomenon, sometimes it expects what is never going to happen, and sometimes it behaves unexpectedly.

Sometimes it feels the pain which happened to others and sometimes never bothers to the continuous pain which eats it like termite.

Sometimes it feels happy for no reason and sometimes not a single reason among many make it smile.

Sometimes while going through its most difficult times and fighting with the toughest enemies, it seems calm and quiet and sometimes it make noise and havoc  for no reason.

Sometimes it makes the complex world easy for others and sometimes become most complex thing for the world.

 

Static Variables in your Life

by Azra Irshad

[language = Javaish]

List<GreatPeople>  greatPeople = new LinkedList<>();

Some people are just like static variables in your life, once they have initialized in your life’s memory they do not allow to give away the value they were initialized with. No matter what, you can always find them, and get their help to resolve the complex algorithms, severe exceptions and mild warnings in your life. As long as your life’s class is loaded they are there and not elected to be garbage collected because there is always a reachable reference to them in your heap and they do not make themselves unavailable for you.

 

This is for all my family members, good friends, good colleagues and some acquaintances…

My Father’s Golden Principles – Syed Irshad Ali

May 23, 2011 at 3:57pm

 by Azra Irshad 

  1. Be honest, Be Original, Be punctual, Be courageous, Be straightforward, Be truthful.
  2. Don’t do injustice with others and don’t let others do injustice with you.
  3. Make your heart bigger as much as possible while giving something to someone.
  4. Choose the same thing for others as you choose for yourself.
  5. Don’t leave any doubt and deficiency in anything you do.
  6. Always keep things simple and straight.
  7. Always keep your surrounding clean.
  8. Forgive and ask for forgiveness but don’t let depraved free.
  9. Take stand for the betterment of yourself, your family, and people you know or don’t know against everything detrimental.
  10. Keep focus on one thing at a time to do your best.
  11. Don’t be ashamed for whatever you have, whoever you are but always try to be the best.
  12. Always Be Thankful to Allah for whatever you have.
  13. Try your best and leave the results on Allah.
  14. Be generous and show happiness when someone come to your home, always welcome your guest with a big heart and serve them the best, no matter who is he , what is his status and how close he is to you and your family.