Monday, February 26, 2018

Sum of 2 elements in array with Target element

import java.util.HashSet;
import java.util.Set;

public class SumElements{

public static void main(String[] args) {
SumElements test = new SumElements();
int[] arr = { 2, 3, 4, 2, 1, 10, -4, 3 }; // Integer array
test.findPairs(arr, 6);
}

// The findPairs method time complexity would be O(n)
public void findPairs(int[] arr, int target) {
if (arr.length < 2) {    //Base-Case (If array length is less than 2, Just return)
return;
}
Set<Integer> set = new HashSet<Integer>(arr.length);

for (int num : arr) {
int result = target - num;
if (!set.contains(result)) {
set.add(num);
} else {
System.out.println("Pairs are: (" + num + " " + result + ")");
}
}
}

}

Time complexity: O(n)

//Output: 
//Pairs are: (4 2)
//Pairs are: (-4 10)
//Pairs are: (3 3)


Wednesday, October 25, 2017

Find Duplicate numbers in an Array and its Count-Java

package Practise;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class FindDublicates {   //Class Name
public static void main(String[] args) {
FindDublicates obj = new FindDublicates();
int[] array = { 13, 3, 22, 44, 12, 13, 3, 3, 13 };  // Array declaration
obj.dublicateMethod(array);
}

public void dublicateMethod(int[] array) {  //Method
   //As MAP takes Key,Value pair; after iterating through the loop,
// it checks if Key has a Value or not. If present it increments the Value
// or else it assign the Key with the number and puts Value as 1.
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
if (array.length > 1) {
for (int i = 0; i < array.length; i++) {
if (map.get(array[i]) != null) {
int count = map.get(array[i]);
map.put(array[i], count + 1);
} else
map.put(array[i], 1);
}
//The following code takes keySet and iterates using Iterator and checks for //condition
// Prints all the number who's key is greater than 1.

Set<Integer> set = map.keySet();
  Iterator it = set.iterator();
    while (it.hasNext()) {
      Object key = it.next();
  if (map.get(key) > 1) {
    System.out.println("The Number is:" +key +": and repeated" +map.get(key) + "                                                                     times");
}

}
}
}
}


Output: The Number is: 3 and repeated 3 times
              The Number is: 13 and repeated 3 times


Monday, August 7, 2017

Blog-Address

www.nk0808blogspot.com

https://nk0808.blogspot.com/

In quest of Mr & Miss Telangana

The second round of audition for Mr & Miss Telangana Fashion pageant was conducted on Sunday at 2O2 lounge in Dilshuknagar. In all, the organizers Hyderabad Models will conduct five auditions to select 40 candidates (20 male & female) who will compete in the finals.
Actress Darshitha Sathwick, Uma Manasa fashion designer, Charan Naid (actor) and Sunitha hair style from Jawed Habib were the jury member of this event. They have selected 4 girls and 4 boys for finals.
"I am feeling that it’s a great opportunity for youngsters and frankly it’s very hard to get placed in this industry to be noticed and Hyderabad models Sunil and Vamshi are giving the perfect opportunity for youngsters of this age, and it’s a great platform to recognize talent. This day I met like 20 or 30 candidates and I know today what sort of talent each one of them has, so I feel it’s a great opportunity. You have to maintain your body tone your physic it's I am not about if someone is fat or not, perhaps whatever size you are but get toned. In addition to this one has be strong this industry as it has lots of failure stories and you will see 70% of the failure and rest to be a success. You have to be strong enough to be a failure as success comes  after failure and that will be the best feeling in the world said Darshitha Sathwick (Actress) ".

-Nihal Kurre
“The moment I entered, I was little worried but, later through my experience in this fashion field I made myself bold and finally I got selected. It was a fantastic experience and one of the best platform to prove myself. The judges were quite friendly & questioning method was good” said Nihal Kurre.
Akshay Mishra, Anil Rathod, Pramod, Nihal Kurre, Navya Reddy, Upanasana Juhi, Varshiniand Yamini were selected for finals.
The event is being organized by owners of Hyderabad models Sunil and Vamshi. Sreeman Nani and Parashuram are the photographers for the whole event.


http://www.metroindia.com/lifestyle/article/23/07/2015/in-quest-of-mr-miss-telangana/9605