This file contains hidden or 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
require 'byebug' | |
class AnagramCountChecker | |
def initialize(str) | |
@str = str | |
end | |
def sort_word(word) | |
word.chars.sort_by { |ch| ch.ord }.join('') |
This file contains hidden or 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
=begin | |
Two words are anagrams of one another if their letters can be rearranged to form the other word. | |
In this challenge, you will be given a string. You must split it into two contiguous substrings, then determine the minimum number of characters to change to make the two substrings into anagrams of one another. | |
For example, given the string 'abccde', you would break it into two parts: 'abc' and 'cde'. Note that all letters have been used, the substrings are contiguous and their lengths are equal. Now you can change 'a' and 'b' in the first substring to 'd' and 'e' to have 'dec' and 'cde' which are anagrams. Two changes were necessary. | |
Input Format | |
The first line will contain an integer, q, the number of test cases. | |
Each test case will contain a string s which will be concatenation of both the strings described above in the problem. |
This file contains hidden or 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 MIT License (MIT) | |
// Copyright (c) 2016 Training 4 Developers, Inc. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM |
This file contains hidden or 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
function Vehicle(speed) { | |
this.speed = speed; | |
} | |
function Car(vehicle_type, speed) { | |
// this._super.call(this, speed); | |
this.speed = speed; | |
this.vehicle_type = vehicle_type; | |
} |
This file contains hidden or 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
var mySingleton = (function () { | |
// Instance stores a reference to the Singleton | |
var instance; | |
function init() { | |
// Singleton | |
// Private methods and variables | |
function privateMethod(){ | |
console.log( "I am private" ); | |
} | |
var privateVariable = "Im also private"; |
This file contains hidden or 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
## Compressing a string, but without corner cases. | |
## e.g. aaaaaaaabbbbbbb ==> a8b7 | |
## abcdef => abcdef | |
def compress_string(str) | |
count = 1 | |
can_be_compressed = false | |
compressed_string = '' | |
i = 1 |
This file contains hidden or 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
function Person(first_name, last_name) { | |
this.first_name = first_name; | |
this.last_name = last_name; | |
} | |
Person.prototype.getFullName = function() { | |
return this.first_name + ' ' + this.last_name; | |
} | |
function Student(studentId, first_name, last_name) { |
This file contains hidden or 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
def longest_consecutive_sequence(a) | |
ans = 0 | |
a.length.times do |i| | |
unless a.include?(a[i] - 1) | |
j = a[i] | |
while(a.include?(j)) do | |
j += 1 | |
end |
This file contains hidden or 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 Duck | |
# def initialize(name) | |
# @name = name | |
# end | |
# def eat | |
# puts "Duck #{@name} eats" | |
# end |
This file contains hidden or 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
let fs = require('fs'); | |
// ConcreteComponent | |
class SimpleWriter { | |
constructor(path) { | |
this.file_path = path; | |
} | |
writeLine(line) { | |
let self = this |
NewerOlder