Snippets Collections
import javax.swing.*;  
public class FirstSwingExample {  
public static void main(String[] args) {  
JFrame f=new JFrame();//creating instance of JFrame  
          
JButton b=new JButton("click");//creating instance of JButton  
b.setBounds(130,100,100, 40);//x axis, y axis, width, height  
          
f.add(b);//adding button in JFrame  
          
f.setSize(400,500);//400 width and 500 height  
f.setLayout(null);//using no layout managers  
f.setVisible(true);//making the frame visible  
}  
}  
# get "/articles?page=2"
request.original_url # => "http://www.example.com/articles?page=2"
import java.util.Stack;

/**
 * Java Program to implement a binary search tree. A binary search tree is a
 * sorted binary tree, where value of a node is greater than or equal to its
 * left the child and less than or equal to its right child.
 * 
 * @author WINDOWS 8
 *
 */
public class BST {

    private static class Node {
        private int data;
        private Node left, right;

        public Node(int value) {
            data = value;
            left = right = null;
        }
    }

    private Node root;

    public BST() {
        root = null;
    }

    public Node getRoot() {
        return root;
    }

    /**
     * Java function to check if binary tree is empty or not
     * Time Complexity of this solution is constant O(1) for
     * best, average and worst case. 
     * 
     * @return true if binary search tree is empty
     */
    public boolean isEmpty() {
        return null == root;
    }

    
    /**
     * Java function to return number of nodes in this binary search tree.
     * Time complexity of this method is O(n)
     * @return size of this binary search tree
     */
    public int size() {
        Node current = root;
        int size = 0;
        Stack<Node> stack = new Stack<Node>();
        while (!stack.isEmpty() || current != null) {
            if (current != null) {
                stack.push(current);
                current = current.left;
            } else {
                size++;
                current = stack.pop();
                current = current.right;
            }
        }
        return size;
    }


    /**
     * Java function to clear the binary search tree.
     * Time complexity of this method is O(1)
     */
    public void clear() {
        root = null;
    }

}
class Solution(object):
    def letterCombinations(self, digits):
        """
        :type digits: str
        :rtype: List[str]
        """
        
# Python3 implementation of the approach 

# Function to sort the array such that 
# negative values do not get affected 
def sortArray(a, n): 

	# Store all non-negative values 
	ans=[] 
	for i in range(n): 
		if (a[i] >= 0): 
			ans.append(a[i]) 

	# Sort non-negative values 
	ans = sorted(ans) 

	j = 0
	for i in range(n): 

		# If current element is non-negative then 
		# update it such that all the 
		# non-negative values are sorted 
		if (a[i] >= 0): 
			a[i] = ans[j] 
			j += 1

	# Print the sorted array 
	for i in range(n): 
		print(a[i],end = " ") 


# Driver code 

arr = [2, -6, -3, 8, 4, 1] 

n = len(arr) 

sortArray(arr, n) 

<?php 
function count_num_finger( $n ) 
{ 
	$r = $n % 8; 
	if ($r == 1) 
		return $r; 
	if ($r == 5) 
		return $r; 
	if ($r == 0 or $r == 2) 
		return 2; 
	if ($r == 3 or $r == 7) 
		return 3; 
	if ($r == 4 or $r == 6) 
		return 4; 
}	 

// Driver Code 
$n = 30; 
echo(count_num_finger($n)); 
 
?> 
<?php 
// PHP program to find nth 
// magic number 

// Function to find nth 
// magic number 
function nthMagicNo($n) 
{ 
	$pow = 1; 
	$answer = 0; 

	// Go through every bit of n 
	while ($n) 
	{ 
	$pow = $pow * 5; 

	// If last bit of n is set 
	if ($n & 1) 
		$answer += $pow; 

	// proceed to next bit 
	$n >>= 1; // or $n = $n/2 
	} 
	return $answer; 
} 

// Driver Code 
$n = 5; 
echo "nth magic number is ", 
	nthMagicNo($n), "\n"; 

// This code is contributed by Ajit. 
?> 
int maxSubArraySum(int a[], int size) 
{ 
int max_so_far = 0, max_ending_here = 0; 
for (int i = 0; i < size; i++) 
{ 
	max_ending_here = max_ending_here + a[i]; 
	if (max_ending_here < 0) 
		max_ending_here = 0; 

	/* Do not compare for all elements. Compare only 
		when max_ending_here > 0 */
	else if (max_so_far < max_ending_here) 
		max_so_far = max_ending_here; 
} 
return max_so_far; 
} 
bookmark
dashboard

Wed Jan 01 2020 19:00:00 GMT+0000 (UTC) https://www.javatpoint.com/java-swing

#java #howto #interviewquestions #mobile
bookmark
dashboard

Tue Dec 31 2019 19:00:00 GMT+0000 (UTC) https://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url

#howto #rubyonrails #webdev #interviewquestions
bookmark
dashboard

Sun Dec 29 2019 20:06:50 GMT+0000 (UTC) https://javarevisited.blogspot.com/2015/10/how-to-implement-binary-search-tree-in-java-example.html#axzz4wnEtnNB3

#java #interviewquestions #search
bookmark
dashboard

Thu Dec 26 2019 18:45:53 GMT+0000 (UTC) https://leetcode.com/problems/letter-combinations-of-a-phone-number/

#python #interviewquestions #interesting
bookmark
dashboard

Thu Dec 26 2019 15:35:22 GMT+0000 (UTC) https://www.geeksforgeeks.org/sort-an-array-without-changing-position-of-negative-numbers/

#python #interesting #arrays #sorting #interviewquestions
bookmark
dashboard

Thu Dec 26 2019 15:18:45 GMT+0000 (UTC) https://www.geeksforgeeks.org/program-count-numbers-fingers/

#php #interesting #interviewquestions #logic
bookmark
dashboard

Wed Dec 25 2019 13:48:42 GMT+0000 (UTC) https://www.geeksforgeeks.org/find-nth-magic-number/

#php #interviewquestions #makethisbetter
bookmark
dashboard

Wed Dec 25 2019 10:57:06 GMT+0000 (UTC) https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/

#c++ #algorithms #interviewquestions #arrays

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension