Skip to content

Instantly share code, notes, and snippets.

{
"cur": "USD",
"id": "71ee43cd974c43e9a6ad59b7386279b8",
"seatbid": [
{
"bid": [
{
"nurl": "http://et-eus.w.inmobi.com/c.asm/HDbA1qWZgLjkBRb21AgUXBS8ARX8BRsBWBgkMDNmOWYwZTQtOTM3ZC00Zjg1LTkyNzUtZjUzMGUwMTA3YjJmHBUEFRgVAhWgBhUCJQAoBnNfb3J0YgATACXKARgYWTI5dExtNTFkQzVwWkM1emRHbGphMlZ5FsCNtwEcHBaAwOiXwMrLnkYW4f3__9_gwP89AAAVGBcAAAAAAIBRQBIUABwSGRUCABbAjbcBGANVU0QW3rut0-9eGfUV6J0B_qsBnKwBtqwByrsBkssBlMsBmssB9ssBmswBnMwBoMwByMwBzMwB1swB1tMB4OIB_OsB5pkC4NcCuIcDIRhcDAABCwABAAAAIDg4YjM3ZWZjZDVmMzRkMzY4ZTYwMzE3YzcwNjk0MmE0CgACAAAAAAAXY2UABAACAAAAAAAAAAAKAAQAAAAAABbjYAoABQAAAAAAEAWQAgAGAAA4FwQAAUBRgAAAAAAABAACP4R64UeuFHsAGNkBAwABBwgAAgAAABEGAAUBLAYABgD6CwAHAAAABTQuMC4wCwAIAAAAA0FQUAgACQAAAAACAAoBBAAMP3iTdLxqfvoLAA8AAAAMTk9fVEFSR0VUSU5HCAASAADgDgsAFAAAACA3OWMxYjcxNTg1ZWE0MmM3OTI3MTEwODJjOTVkNTdmMQIAFQAIABYAAAAACwAXAAAAAzYuMAIAGAACABkAAgAbAAYAHAAAAgAdAQIAIAACACEBCgAlAAAAAAAAAAALACgAAAASY29tLm51dC5pZC5zdGlja2VyABiTAgoAAQAAAAAAAAAACwACAAAA9AsAAQAAABJjb20ubn
class Solution {
public Node flatten(Node head) {
Node node=head;
while(node!=null){
node=insert(node.child,node,node.next);
}
return head;
}
public Node insert(Node child,Node pre,Node next){
if(child==null)return next;
@Riku-tei
Riku-tei / 1.9Solution.java
Created May 31, 2020 15:28
1.9 String Rotation: Assume you have a method i5Substring which checks ifone word is a substring of another. Given two strings, 51 and 52, write code to check if 52 is a rotation of 51 using only one call to isSubstring (e.g., U waterbottleuis a rotation ofu erbottlewat U ).
package com.tei;
public class StringRotation {
boolean isRotation(String str1, String str2) {
if (str1.length() == str2.length() && str1.length() > 0) {
return isSubstring(str1 + str1, str2);
}
return false;
}
}
@Riku-tei
Riku-tei / 1.8Solution.java
Last active May 31, 2020 15:18
1.8 Zero Matrix: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.
package com.tei;
import java.util.Arrays;
public class ZeroMatrix {
static void setZeroMatrix(int[][] matrix) {
boolean[] rowHaszero = new boolean[matrix.length];
boolean[] columnHaszero = new boolean[matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
@Riku-tei
Riku-tei / 1.7Solution.java
Created May 31, 2020 14:15
1.7 Rotate Matrix: Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
package com.tei;
import java.util.Arrays;
public class Rotation {
static boolean rotate(int[][] matrix) {
if (matrix.length == 0 || matrix.length != matrix[0].length) {
return false;
}
int n = matrix.length;
@Riku-tei
Riku-tei / 1.6Solution.java
Created May 31, 2020 07:29
1.6 String Compression: Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3 . If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only upperca…
package com.tei;
public class compresseddString {
static String compress(String str) {
StringBuilder sen = new StringBuilder();
int countsecutive = 0;
for (int i = 0; i < str.length(); i++) {
countsecutive++;
if (i == str.length() - 1 || str.charAt(i) != str.charAt(i + 1)) {
sen.append(str.charAt(i));
@Riku-tei
Riku-tei / 1.5Solution.java
Created May 30, 2020 09:57
1.5 One Away: There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away. EXAMPLE pale, ple -) true pales, pale -) true pale, bale -) true pale, bae -) false
package com.tei;
public class Oneaway {
boolean isOneAway(String str1, String str2) {
if (str1.length() == str2.length()) {
return isReplace(str1, str2);
}
if (str1.length() + 1 == str2.length()) {
return isInsert(str1, str2);
}
@Riku-tei
Riku-tei / 1.4Solution1.java
Last active May 30, 2020 09:12
1.4 Palindrome Permutation: Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words. EXAMPLE Input: Tact Coa Output: True (permutation…
package com.tei;
public class PalindromePermutation {
public boolean isPermutationofPalindrome(String str) {
String strlow = str.toLowerCase();
int[] arr=buildtable(strlow);
return countOdd(arr);
}
boolean countOdd(int[] arr) {
@Riku-tei
Riku-tei / 1.3solution.java
Last active May 30, 2020 00:12
Write a method to replace all spaces in a string with '%20': You may assume that the string has sufficient space at the end to hold the additional characters, and that you are given the "true" length of the string. (Note: if implementing in Java, please use a character array so that you can perform this operation in place.)
public class URLify {
public static void urlify(char[] str, int length) {
int blank = 0;
for (int i = 0; i < length; i++) {
if (str[i] == ' ') {
blank++;
}
}
int back = length + blank * 2;
for (int i = length - 1; i >= 0; i--) {
@Riku-tei
Riku-tei / 1.2 solution1.java
Created May 28, 2020 05:55
1.2 Check Permutation: Given two strings, write a method to decide if one is a permutation of the other.
String sort(String s) {
char[] content = s.toCharArray();
Arrays.sort(content);
return new String(content);
}
boolean permutation1(String s, String t) {
if (s.length() != t.length()) {
return false;
}