Skip to content

Instantly share code, notes, and snippets.

View manojnaidu619's full-sized avatar
🎯
Focusing

Manoj Kumar manojnaidu619

🎯
Focusing
  • Bangalore,India
View GitHub Profile
@manojnaidu619
manojnaidu619 / matrix_transpose.rb
Created July 5, 2019 08:44
Leetcode Solution for "Transpose Matrix" problem in Ruby
def transpose(a)
return a if a.empty?
sub = a[0].size
b = Array.new
c = Array.new
if a.size == 1
a[0].each do |i|
b << [i]
end
p b
@manojnaidu619
manojnaidu619 / bitwise_complement.rb
Last active July 4, 2019 17:46
Leetcode Solution for "Number Complement" problem in Ruby
=begin
687.to_s(2) # "1010101111"
"1010101111".to_i(2) # 687
=end
def find_complement(num)
num = num.to_s(2).chars
num.map!{|i| i.to_i}
for x in 0..num.size-1 do
if num[x]==0
@manojnaidu619
manojnaidu619 / new_sort.rb
Created July 4, 2019 16:40
Ruby Different way of sorting array!
nums = [5,4,3,2,1,1]
a = Array.new
until nums.empty?
min = nums.min
step = nums.count(min)
if step > 1
step.to_i.times do
a << min
end
nums.delete(min)
@manojnaidu619
manojnaidu619 / search_insert_position.cpp
Created July 4, 2019 14:57
Leetcode Solution for "Search Insert Position" problem in CPP
// Solved using Binary Search implementation
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int first=0;
int last = nums.size()-1;
int mid = (first+last)/2;
while(first<=last){
@manojnaidu619
manojnaidu619 / find_height_&_leaf_BST.cpp
Last active July 3, 2019 09:10
Getting height & leaf nodes of Left and Right subtree in a BST
#include <iostream>
using namespace std;
struct Node{
struct Node *lchild;
int data;
int height;
struct Node *rchild;
}*root=NULL,*lleaf=NULL,*rleaf=NULL; // Pointing to Left and Right leaf nodes in BST
@manojnaidu619
manojnaidu619 / meta-tags.md
Created July 3, 2019 06:35 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">
@manojnaidu619
manojnaidu619 / cycle-loop_in_SLL.cpp
Created July 2, 2019 15:32
Leetcode solution for "Linked List Cycle" problem
class Solution {
public:
bool hasCycle(ListNode *head) {
struct ListNode *p=head, *q=head;
if(!head || head->next==NULL){
return false;
}
while(p!=NULL && p->next!=NULL){
p=p->next->next;
q=q->next;
@manojnaidu619
manojnaidu619 / del_node_in_SLL.cpp
Created July 2, 2019 15:30
Leetcode solution for "Delete Node in a Linked List" problem in CPP
class Solution {
public:
void deleteNode(ListNode* node) {
struct ListNode *p=node;
if(p->next != NULL){
p->val = p->next->val;
p->next = p->next->next;
}else{
return;
}
@manojnaidu619
manojnaidu619 / k_frequent_elements.rb
Created July 2, 2019 12:19
Leetcode Solution for " Top K Frequent Elements " problem in Ruby
def top_k_frequent(nums, k)
order = Hash.new
nums.each do |i|
order[i.to_s] = nums.count(i).to_i
end
keys = order.sort_by {|key, value| value}.reverse.to_h.keys
keys.map!{|i| i.to_i}
p keys[0...k]
end
@manojnaidu619
manojnaidu619 / remove_val_from_SLL.cpp
Created July 1, 2019 13:43
Leetcode Solution for "Remove Linked List Elements" problem in CPP
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
struct ListNode *p = head, *q=NULL;
if(head==NULL){
return head;
}
while(p->val == val && p->next!=NULL){
p=p->next;
head = p;