This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Strings J = types of stones that are jewels | |
# String S = stones you have | |
# Input | |
# J = "aA", S = "aAAbbbb" | |
# Output | |
# 3 | |
# create a dictionary where the key is the char and the value is the number of occurrences | |
def jewels(S, J): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. | |
Given two integers x and y, calculate the Hamming distance. | |
Note: | |
0 ≤ x, y < 231. | |
Input: x = 1, y = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Jadoo hates numbers, but he requires to print a special | |
number "420" to recharge the equation of life. He asks | |
your help to print the number but Since he hates numbers, | |
he asks you to write the program such that there would not | |
be any number in the code. | |
''' | |
# Write your code here | |
print(sum(ord(c) for c in 'Jado&')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# decision tree that creates branches for every possible outcome | |
from sklearn import tree | |
# list of lists -- each value is the length, width and shoe size | |
X = [[181,80,44],[177,70,43],[160,60,38], | |
[154,54,37],[166,65,40],[190,90,47], | |
[175,64,39],[177,70,40],[159,55,37], | |
[171,75,42],[181,85,43]] | |
Y = ['male', 'female', 'female', 'female', 'male', 'male', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Initially, there is a Robot at position (0, 0). Given a sequence of its | |
moves, judge if this robot makes a circle, which means it moves back to | |
the original place. | |
The move sequence is represented by a string. And each move is represent | |
by a character. The valid robot moves are R (Right), L (Left), U (Up) and | |
D (down). The output should be true or false representing whether the | |
robot makes a circle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def mergeTrees(self, t1, t2): | |
""" | |
:type t1: TreeNode | |
:type t2: TreeNode | |
:rtype: TreeNode | |
""" | |
if not t1: | |
return t2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
"Given an integer number, write a function | |
that returns true if there are any odd digits in the | |
number; e.g. 2468 -> false, 2478 -> true" | |
''' | |
class Solution(): | |
def containsOdd(self,n): | |
return any([int(x)%2 for x in list(str(n))]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Instantiate512Cubes : MonoBehaviour { | |
public GameObject _sampleCubePrefab; | |
private GameObject[] _sampleCube = new GameObject[512]; | |
public float _maxScale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
[RequireComponent(typeof(AudioSource))] | |
public class AudioPeer : MonoBehaviour { | |
AudioSource _audioSource; | |
// from a sound theory spectrum standpoint all seven of those buckets are remapped to 512 values | |
public static float[] _samples = new float[512]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write a function to tell if a full deck of cards is a single riffle of two other halves, half1 and half2 | |
import random | |
from collections import deque | |
h1 = deque(random.sample(range(1, 27), 26)) | |
h2 = deque(random.sample(range(27, 53), 26)) | |
print(h1) | |
print(h2) | |
shuffled_deck = deque(random.sample(range(1, 53), 52)) |
OlderNewer