Skip to content

Instantly share code, notes, and snippets.

View ZakriaJanjua's full-sized avatar
🦾
Producing

Zakria Janjua ZakriaJanjua

🦾
Producing
View GitHub Profile
@ZakriaJanjua
ZakriaJanjua / MIME_Type.py
Last active January 30, 2022 12:18
Coding Games MIME Type challenge. 100% solution
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input()) # Number of elements which make up the association table.
q = int(input()) # Number Q of file names to be analyzed.
emlist = {}
for i in range(n):
@ZakriaJanjua
ZakriaJanjua / isChild.js
Created January 30, 2022 12:19
Robor Coding Challenge Q1.
s1 = "abcd"
s2 = "abdc"
function isChild(str1, str2) {
let result = []
let count = 0
for (let i = 0; i < str1.length; i++) {
if (str1[i] === str2[count]) {
result.push(str2[count])
count++
@ZakriaJanjua
ZakriaJanjua / Counter.sol
Created January 31, 2022 10:44
counter function in solidity
pragma solidity >=0.7.0 <0.9.0;
contract Counter {
uint public count = 0;
// function getCount() public view returns(uint) {
// return count;
// }
function incrementCount() public {
count++;
@ZakriaJanjua
ZakriaJanjua / Arrays.sol
Created January 31, 2022 10:44
Arrays and 2dArrays in solidity
pragma solidity >=0.7.0 <0.9.0;
contract MyContract {
uint[] public intArray = [1,2,3];
string[] public stringArray = ["a","b", "c", "d"];
string[] public values;
uint[][] public my2dArray = [ [1,2,3,4], [5,6,7,9] ];
function pushValues(string memory _value) public {
values.push(_value);
@ZakriaJanjua
ZakriaJanjua / Mapping.sol
Created January 31, 2022 10:45
mapping and nested mapping in solidity
pragma solidity >=0.7.0 <0.9.0;
contract Mapping {
mapping(uint => Book) public books;
//nested mapping
mapping(address => mapping(uint8 => Book)) public myBooks;
struct Book {
@ZakriaJanjua
ZakriaJanjua / Payment.sol
Created January 31, 2022 10:46
payments receiving in solidity
pragma solidity >=0.7.0 <0.9.0;
contract Hotel {
enum Status { Vacant, Occupied }
Status currentStatus;
event Occupy(address _occupant, uint _value);
address payable public owner;
constructor() {
owner = payable(msg.sender);
@ZakriaJanjua
ZakriaJanjua / Cipher.js
Last active April 20, 2022 19:48
Robor Systems Coding Challenge Q2
const string = "abcdefghijklmnopqrstuvwxyz"
function cipher(str, k) {
let first = []
let second = []
for (let i = k; i < str.length; i++) {
second.push(str[i])
}
for (let i = 0; i < k; i++) {
@ZakriaJanjua
ZakriaJanjua / Stocks_Interperse.py
Last active April 20, 2022 19:47
Coding challenge: find the greatest profit of the given stocks and intersperse the result with the given challenge_token
arr = [44, 30, 24, 32, 35, 30, 40, 38, 15] #16
arr2 = [10, 9, 8, 2] #-1
arr3 = [10, 12, 4, 5, 9] #5
arr4 = [14, 20, 4, 12, 5, 11] #8
def possibility(array):
for i in range(0, len(array)):
try:
if (array[i] < array[i+1]):
return True
@ZakriaJanjua
ZakriaJanjua / StringChallenge.js
Created May 21, 2022 18:16
Take a string and invert the case of each character. If the English characters in the string are wrapped between numbers then switch the numbers and if there is any other character then do not switch them.
function StringChallenge(str) {
// code goes here
let result = ""
str = reversing(str)
for (let i = 0; i < str.length; i++) {
let current = str[i].charCodeAt(0)
if (current >= 65 && current <= 90) {
result = result + str[i].toLowerCase()
} else if (current >= 97 && current <= 122) {
@ZakriaJanjua
ZakriaJanjua / CountCharacters.py
Created May 22, 2022 18:23
Take a string as input and count the numbers of characters in their occurrence and return the result with their number of occurrences and the letter.
def countCharacters(string):
single = []
whole = []
result = ""
for i in string:
if (len(single) == 0):
single.append(i)
elif (i == single[0]):
single.append(i)
else: