Skip to content

Instantly share code, notes, and snippets.

View vasujain's full-sized avatar

Vasu vasujain

View GitHub Profile
@vasujain
vasujain / RotateCharArray.java
Last active April 8, 2020 19:37
Rotate CharArray by k places left or right
// Can be run at https://coderpad.io/sandbox
import java.io.*;
import java.util.*;
import org.junit.*;
/** Rotate characters in string s, ‘r’ times without creating a copy
* (i.e. change the supplied string in place).
*
* r > 0 - rotate right
import java.io.*;
import java.util.*;
import org.junit.Assert;
class Solution {
public static void main(String[] args) {
int oranges[][] = {
{2, 1, 0, 2, 1},
{1, 0, 1, 2, 1},
{1, 0, 0, 2, 1}
class StringIterator {
Stack<Character> stack = new Stack<>();
public StringIterator(String compressedString) {
int loop = 0;
int loopLen = 0;
boolean isPrevNum = false;
for(int i=compressedString.length()-1; i>=0; i--) {
int currentChar = compressedString.charAt(i) - '0';
if(currentChar >= 0 && currentChar <= 9) {
if(isPrevNum) {
@vasujain
vasujain / cloudSettings
Last active August 24, 2018 05:41
vscode-settings
{"lastUpload":"2018-08-24T05:41:10.896Z","extensionVersion":"v3.0.0"}
package codezilla.leetcod3;
import org.junit.Assert;
public class LC8_StringToInt {
public static void main(String[] args) {
Assert.assertEquals(1, myAtoi("+1"));
Assert.assertEquals(-42, myAtoi(" -42"));
Assert.assertEquals(42, myAtoi("42"));
import org.junit.Assert;
public class RotatedDigits {
public static void main(String[] args) {
Assert.assertEquals(4, rotatedDigits(10));
}
public static int rotatedDigits(int N) {
int inValidNums = 0;
char[] rotateSelf = new char[]{'0', '1', '8'};
/*
You're now a baseball game point recorder.
Given a list of strings, each string can be one of the 4 following types:
Integer (one round's score): Directly represents the number of points you get in this round.
"+" (one round's score): Represents that the points you get in this round are the sum of the last two valid round's points.
"D" (one round's score): Represents that the points you get in this round are the doubled data of the last valid round's points.
"C" (an operation, which isn't a round's score): Represents the last valid round's points you get were invalid and should be removed.
Each round's operation is permanent and could have an impact on the round before and the round after.
@vasujain
vasujain / twilio_api.js
Created September 25, 2016 07:23
Twilio Text Call
function twilioCall() {
var request = require("request");
var basicAuthToken = "Basic " + twilio.basicAuthToken;
var textBody = twilio.textBody;
var options = { method: 'POST',
url: twilio.apiUrl,
headers:
{ 'content-type': 'application/x-www-form-urlencoded',
authorization: basicAuthToken
},
@vasujain
vasujain / argentum_order_webhook.json
Created May 9, 2016 21:01
Argentum Order Webhook
{
"id": "WH-0P8978067F3103837-80650342HJ8089941",
"create_time": "2016-05-09T17:29:18Z",
"resource_type": "checkout-order",
"event_type": "CHECKOUT.ORDER.PROCESSED",
"summary": "A checkout order was processed",
"resource": {
"id": "19S86694A9334040A",
"intent": "SALE",
"payment_details": {
# Parses YouTube URLs directly or from iframe code. Handles:
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI)
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI)
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">)
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...)
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
$5 #=> the video ID
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo