NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

1. Code Compiler Output
class Result {
static boolean match(char c1,char c2) {
if(c1=='{' && c2=='}') { return true;
}
if(c1=='(' && c2==')') {
return true; }
if(c1=='[' && c2==']') { return true;
}
return false; }
static boolean compilerOutput(String code) { Stack<Character> stack = new Stack<Character>();
char[] ch = code.toCharArray(); for(char i:ch) {
if(i=='{'||i=='('||i=='[') { if(i=='{') {
stack.push('{'); }
if(i=='(') { stack.push('(');
} if(i=='[') {
stack.push('['); }

} if(i=='}'||i==')'||i==']') {
if(stack.empty()==false) { if(match(stack.peek(),i)) {
stack.pop(); }
}
else {
return false; }
} }
if(stack.empty()==true) { return true;
}
return false; }
}
2. Data Collection By Telecom Company
class Result {
static int collectData(int height[], int n) {
Stack<Integer> stack = new Stack<Integer>(); int sum = 0;
stack.push(height[0]);

for(int i=1;i<n;i++) { if(stack.empty()==true) {
stack.push(height[i]);
continue; }
while(stack.empty()==false && stack.peek()<height[i]) { sum+=height[i];
stack.pop();
}
stack.push(height[i]); }
while(stack.empty()==false) { sum = sum-1;
stack.pop();
}
return sum; }
}
class Result {
static Node removeDupsDLL(Node head) {
Node curr = head;
while(curr!=null && curr.next!=null) {
if(curr.data==curr.next.data) { curr.next = curr.next.next; continue;
3. Remove Duplicates from a sorted doubly linked list

}
curr = curr.next; }
return head; }
}
4. Count the Number of Nodes in Circular Linked List
class Result {
static int countNodes(Node head) {
if(head==null) { return 0;
} if(head.next==null) {
return 1; }
Node curr = head.next; int count = 1; while(curr!=head) {
count++;
curr = curr.next; }
return count; }
}

5. Maximum Frequency in a sequence
class Result {
static int maxFrequency(int A[], int n) {
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
for(int i:A) { if(hm.containsKey(i)) {
hm.put(i,hm.get(i)+1); }
else { hm.put(i,1);
} }
int val = -1; int key = A[0];
for(Map.Entry<Integer,Integer> entry:hm.entrySet()) { if(entry.getValue()>val) {
val = entry.getValue();
key = entry.getKey(); }
if(entry.getValue()==val) { if(entry.getKey()<key) { val = entry.getValue();
key = entry.getKey();

} }
}
return key; }
}
6. Count frequency of each character
class Result {
static void countFrequency(String str) {
HashMap<Character,Integer> hm = new HashMap<Character,Integer>();
char[] ch = str.toCharArray();
for(char i:ch) { if(hm.containsKey(i)) {
hm.put(i,hm.get(i)+1); }
else { hm.put(i,1);
} }
for(char i:ch) { if(hm.containsKey(i)) {
System.out.print(i + Integer.toString(hm.get(i))+" "); }

hm.remove(i); }
} }
class Result {
static int highlightedBrackets(String expr) {
Stack<Character> stack = new Stack<Character>(); int count = 0;
char[] ch = expr.toCharArray();
for(char i:ch) { if(i=='{') {
stack.push('{'); }
if(i=='}') { if(stack.empty()==false){
stack.pop(); }
else { stack.push('{'); count++;
} }
}
if(stack.size()%2!=0) {
7. Intelligent Code Editor

return -1; }
return count+stack.size()/2; }
}
* * * * * * */
/* * * * * * * *
8. Delete Nodes greater than X
/*
class Node {
int data;
Node next; };
The above class defines the linked list node.
Complete the 'deleteGreater' function below. @params
head -> head of the linked list X -> an integer
@return
The head of a new list, in which no element (node) should
have value greater than X. */
static Node deleteGreater(Node head, int X) { while(head!=null && head.data>X) {

head = head.next; }
Node curr = head; Node prev = head; while(curr!=null) {
if(curr.data>X) { prev.next = curr.next;
}
else {
prev = curr; }
curr = curr.next; }
return head; }
9. Nth Fibonacci Number Modulo M
class Result {
static long Fibbo(int n,int m) {
if(n==0) { return n%m;
} if(n==1) {
return n%m; }
long a = 0; long b = 1;

long c = 0;
for(int i=2;i<=n;i++) {
c = ((a%m)+(b%m))%m; a = b;
b = c;
} return c;
}
static int nthFibonacciTerm(int n, int m){
int res = (int)Fibbo(n,m); return res;
} }
10. Delete a Node in Linked list given access to only that Node
class Result {
static void deleteNode(Node n1) {
if(n1==null){ return;
}
if(n1.next==null) {
return; }

Node next = n1.next.next; n1.data = n1.next.data; n1.next = next;
} }
static int isCircular(Node head) { if(head==null) {
return 1; }
Node slow = head; Node fast = head;
while(fast!=null && fast.next!=null) { slow = slow.next;
fast = fast.next.next; if(slow==fast) {
break; }
}
if(slow==fast && slow==head) { return 1;
}
return 0;}
11. Given list is circular or not
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.