Somendra Raj
BAN USER
Full java code
package org.sr;
class Node {
Node left;
Node right;
int data;
public Node(int data) {
this.data = data;
this.left = this.right = null;
}
}
public class NthLargestNodeInBST {
/*
* static int curr; static int nThSmallest;
*
* static int getNthSmallestNumber( Node root, int n) { curr = n; helper(root);
* return nThSmallest; }
*
* static void helper(Node root) { if (root != null) { helper(root.left);
* curr--; if (curr == 0) { nThSmallest = root.data; return; }
* helper(root.right); }
*
* }
*/
static int curr;
static int nThLargest;
static int getNthSmallestNumber(Node root, int n) {
curr = n;
helper(root);
return nThLargest;
}
static void helper(Node root) {
if (root != null) {
helper(root.right);
curr--;
if (curr == 0) {
nThLargest = root.data;
return;
}
helper(root.left);
}
}
public static void main(String args[]) {
Node root = new Node(5);
root.left = new Node(3);
root.right = new Node(7);
root.left.left = new Node(2);
root.left.right = new Node(4);
root.right.left = new Node(6);
root.right.right = new Node(8);
System.out.println(getNthSmallestNumber(root, 1));
System.out.println(getNthSmallestNumber(root, 2));
System.out.println(getNthSmallestNumber(root, 3));
}
}
I think this will work....
static int maxDistance(int[] arr) {
if (arr == null || arr.length < 2)
return -1;
int start = 0;
int end = arr.length - 1;
while (start < end) {
if (arr[start] < arr[end]) {
return end - start;
}
end--;
}
return -1;
}
static void union(int arr1[], int[] arr2) {
int i = 0, j = 0, k = 0;
List<Integer> list = new ArrayList<>();
boolean flag = true;
while (flag) {
if (arr1[i] == arr2[j]) {
list.add(arr1[i]);
i++;
j++;
} else if (arr1[i] < arr2[j]) {
list.add(arr1[i]);
i++;
} else {
list.add(arr2[j]);
j++;
}
if (j == arr2.length) {
flag = false;
}
}
if (arr1.length > arr2.length) {
int min = arr2.length;
for (int x = min; x < arr1.length; x++) {
list.add(arr1[x]);
}
} else {
int min = arr1.length;
for (int x = min; x < arr2.length; x++) {
list.add(arr2[x]);
}
}
System.out.println();
for (Integer x : list) {
System.out.print(x + " ");
}
}
package Algorithm.Bit;
public class ElementAppearsOnce {
static int getInteger(int arr[], int n){
int result = 0;
int x, sum;
for(int i=0;i<32;i++){
sum = 0;
x = (1<<i);
for(int j=0;j<n;j++){
if((arr[j] & x) ==0)
sum++;
}
if(sum%3==0)
result = result|x;
}
return result;
}
public static void main(String args[]){
int arr[] = {12, 1, 12, 3, 12, 1, 1, 2, 3, 2, 2, 3, 7};
int n = arr.length;
int res = getInteger(arr, n);
System.out.println(res);
}
}
package Algorithm.Bit;
public class ElementAppearsOnce {
static int getInteger(int arr[], int n){
int result = 0;
int x, sum;
for(int i=0;i<32;i++){
sum = 0;
x = (1<<i);
for(int j=0;j<n;j++){
if((arr[j] & x) ==0)
sum++;
}
if(sum%3==0)
result = result|x;
}
return result;
}
public static void main(String args[]){
int arr[] = {12, 1, 12, 3, 12, 1, 1, 2, 3, 2, 2, 3, 7};
int n = arr.length;
int res = getInteger(arr, n);
System.out.println(res);
}
}
5 sub
- Somendra Raj June 21, 2017it will print [99]
- Somendra Raj June 17, 2017#include<stdio.h>
int main(){
int n,sqroot,i,j;
printf("Enter the number: \n");
scanf("%d", &n);
if(n>10000){
printf("Invalid Entry number should be less than 10000\n");
//return ;
}
else{
for(i=1;i<=100;i++){
if(i *i == n){
sqroot = i;
break;
}
}
if(sqroot == i){
printf("Number is perfect square and square root is %d :", sqroot);
}else{
printf("Not perfect square");
}
}
return 0;
}
Repsandrafdenn, Associate at CareerCup
Je suis développeur web dans une société de Wild Oats Markets, j'adore faire du shopping et j'ai une ...
RepPennyRMullins, xyz at Aspire Systems
I am a creative Interior Designer with 2+ years of experience building customized solutions for residential and commercial clients. Intuitively ...
Repfrancesdpayne, AT&T Customer service email at Cavium Networks
I am Frances Payne from Jacksonville, United States. I am working as a Rental manager in Magna Gases company. I ...
Repselindareese, Animator at Agilent Technologies
I am Selinda a Music teacher and composer with 6+ years of experience with an in depth knowledge of music ...
Repdaysidbass, Junior programmer at AppPerfect
I have 5 years international experience working in the UK. I assist companies to gain greater value out of their ...
RepHello, I am Sherri from Orangeburg. I am working as a Nurse in Kleinhans Hospital. I like painting, reading, and ...
Repjuanajcox4, Python Developer at Axiom Sources
I have 2 years of experience in designing and implementing computer algorithms or models for creating, displaying, and processing various ...
Repalinehchavez, SHOT 1500 NIGHT 5000 Call girls in Munirka Metro 9711794795 at Apple
Hi, I am Aline From New York USA. I am working as a Real estate rental agent in an Energy ...
Repbradybally973, Computer Scientist at AMD
I am a network administrator. I live in Washington USA .My responsibility includes maintaining computer infrastructures with emphasis on local ...
Repcardiroy, Backend Developer at Accolite software
Hi,I am from Taxes, USA. Enthusiastic multilingual translator with years involvement with Spanish-English translations.Looking to additionally improve interpretation ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
Repharoldjmaloney, Accountant at ASU
Hi, I am a Computer systems administrator from texas. Experienced in running a wide variety of software development Company. Looking ...
Repannaharricks, Computer Scientist at ABC TECH SUPPORT
Hi, I am a Social worker to help people handle everyday life problems. I also assist people who have issues ...
Repman254183, Project Leader at GoDaddy
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
RepMelissaJoy, Associate at Bocada
Hi, I am Melissa, a purchasing agent from Texas. Kind of a good Samaritan, terrible athlete, but extremely blessed in ...
Repmelissattaylor, AT&T Customer service email at Bankbazaar
Je suis membre participant du chapitre de Virginie de l'Association nationale du travail social. J'aime lire et écrire ...
Repaliciajdew, Integration Software Engineer at Absolute Softech Ltd
I have a strong base in marketing and I believe in focused strategies that bring brands to their relevant audiences ...
Replestermauldin, Assignment editor at Royal Gas
I am Lester Assignment editor . I am responsible for organizing the assignment desk to operate around the clock. I often ...
Repkarinkwalton, Backend Developer at Broadsoft
I am working as a Support clerk in an MVP Sports company. I love traveling and exploring facts about technology ...
Repmakaylaangwin, Backend Developer at Abs india pvt. ltd.
I'm part owner of Bloom Floral Land, an Australian floral design company. Life is really short, try to smile ...
Repmyershllims, abc at ASAPInfosystemsPvtLtd
Hiii, I am Myers and I am from Elizabeth. I am working as a Product designer designing most things I ...
Repclairetsmith49, AT&T Customer service email at ADP
Hello, I am Claire and work as a Human resources and I am responsible for recruiting, screening, interviewing and how ...
Repmarkemorgan007, Applications Developer at Big Fish
I am Mark From Fresno city in USA.I working as a tour guide and also help for make a ...
RepAvikaEthan, Data Engineer at Adjetter Media Network Pvt Ltd.
Avika Ethan has five years of experience collecting physical and biological data in California streams and rivers. In the field ...
- Somendra Raj September 29, 2020