Posts
Jewel Game (Hack The Interview V : Asia-Pacific)
- Get link
- Other Apps
Contest Link import java.util.*; class Solution{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ String jewels = sc.next(); StringBuilder s = new StringBuilder(); s.append(jewels); int count = 0; while(true){ int temp = 0; for(int i=0;i<s.length()-1;i++){ if(s.charAt(i)==s.charAt(i+1)){ count++; s.deleteCharAt(i); s.deleteCharAt(i); temp++; } } if(temp==0){ break; } } System.out.println(count); } } }
The XOR Problem (Hack The Interview V : Asia-Pacific)
- Get link
- Other Apps
Contest Link import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result { /* * Complete the 'maxXorValue' function below. * * The function is expected to return a STRING. * The function accepts following parameters: * 1. STRING x * 2. INTEGER k */ public static String maxXorValue(String x, int k) { StringBuilder s = new StringBuilder(); int n = 0; int i = 0; for(i=0;i<x.length();i++){ if(n<k){ if(x.charAt(i)=='0'){ s.append('1'); n += 1; } else{ s.append('0'); }
New KeyBoard (Hack The Interview V : Asia-Pacific)
- Get link
- Other Apps
Contest Link import java.util.*; class Solution{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String s = sc.next(); StringBuilder res = new StringBuilder(""); boolean isPressed = false; int count = 0; boolean cursorStart = false; ArrayList<Character> c = new ArrayList<>(); for(int i=0;i<10;i++){ c.add((char)i); } for(int i=0;i<s.length();i++){ if(s.charAt(i)=='<'){ res = res.reverse(); cursorStart = true; continue; } else if(s.charAt(i)=='>'){ if(cursorStart == true){ res = res.reverse(); cursorStart = false; } continue; } else if(s.charAt(i)=='*'){ res.delete(res.length()-1, res.length());
Hackerrank Solution :- print-the-elements-of-a-linked-list
- Get link
- Other Apps
Question Link import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { static class SinglyLinkedListNode { public int data; public SinglyLinkedListNode next; public SinglyLinkedListNode(int nodeData) { this.data = nodeData; this.next = null; } } static class SinglyLinkedList { public SinglyLinkedListNode head; public SinglyLinkedListNode tail; public SinglyLinkedList() { this.head = null; this.tail = null; } public void insertNode(int nodeData) { SinglyLinkedListNode node = new SinglyLinkedListNode(nodeData); if (this.head == null) { this.head = node; } else { this.tail.next = node; } this.tail = node; } } // Complete the pr
Seive of Eratosthenis algorithm to generate prime numbers.
- Get link
- Other Apps
Sieve of Eratosthenis Algorithm:- 1. Create a list of consecutive integers from 2 to n: (2, 3, 4, …, n). 2. Initially, let p equal 2, the first prime number. 3. Starting from p2, count up in increments of p and mark each of these numbers greater than or equal to p2 itself in the list. These numbers will be p(p+1), p(p+2), p(p+3), etc.. 4. Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, let p now equal this number (which is the next prime), and repeat from step 3. <--> When the algorithm terminates, all the numbers in the list that are not marked false are prime. If you want the code for it then comment down.
IDEs needed for various programming languages
- Get link
- Other Apps
IDE stands for Integrated Development Environment. An IDE consists of a text editor to write the code, a console to view the output, a compiler at backend to process (i.e. compile and run) the code and several necessary buttons to compile, run, etc. Here are some of the IDEs to start with various programming languages :- 1. C, C++ :- CLion , DevC++ , CodeBlocks , TurboC++ . 2. Java :- Eclipse , IntelliJ IDEA , NetBeans , BlueJ . 3. Python :- PyCharm , Spyder . There are some editors which can be used to compile and run the code of many languages by downloading extensions. Some of them are :- Sublime Text , Notepad++ , Visual Studio Code , Atom etc. Top computer books